views:

1522

answers:

4

Hi,

i want to use doPostBack function in my link.When user clicks it,it wont redirect to another page and page will be postback.I am using this code but it doesnt function.Where do i miss?

< a id="Sample" href="javascript:__doPostBack('__PAGE','');">

function __doPostBack(eventTarget, eventArgument)

{ var theform = document.ctrl2

       theform.__EVENTTARGET.value = eventTarget

       theform.__EVENTARGUMENT.value = eventArgument

       theform.submit()
   }
A: 

__doPostBack is an auto-generated function that ensures that the page posts-back to the server to maintain page state. It's not meant to be used for redirection...

You could either use window.location.href="yourpage.aspx" on javascript or Response.Redirect("yourpage.aspx") at server side on the page you are doing the postback.

Sergio
+1  A: 

Try this :

System.Web.UI.HtmlControls.HtmlAnchor myAnchor = new System.Web.UI.HtmlControls.HtmlAnchor();
string postbackRef = Page.GetPostBackEventReference(myAnchor);
myAnchor.HRef = postbackRef;
Canavar
A: 

Why would you want to cause a postback manually? If your information is out of date you can consider an AJAX Timer.

tsilb
A: 

ok but i am using link in my datagrid and when user clicks the link,i want to postback only datagrid content(So the link will change datagrid content and it is not a column.it is a simple text like wikipedia's.The link is created in Run Time by this code,I am using UpdatePanels).

str = regex.Replace(str, "(look: < a href=""javascript:" & Page.GetPostBackEventReference(Me) & ">< font color=""#CC0000"">$1 < /a> )")

If i use,window.location.href,it will postback all page.My target is to postback only datagrid(Ofcourse by taking Link's text as output too).I dont use Frames,and link is not a button.How can i do it?

Are you using Update panel or something like that ? What you mean by posting only datagrid ?
Canavar
Actually,i couldnt do what i wanted.By your solution,i did postback Page and that was my question. Now second question,Is it possible to postback just a control by your Function?(Not All Page)? Thanks for your help
You can do it with this two ways : First way, you can use Ajax UpdatePanel to post only controls that it includes. Or you can use an iframe and post only referenced page.
Canavar
Yes,iframe is ok but i cant understand how i can do it with UpdatePanel.Because i change "text" to "link" in run time and when i push the link in datagrid's cell,it postbacks page(Normal because i give ahref).So The Link is not Like a Simple LinkColumn,it is like the links in wikipedia.
so in this case,i think iframes are the best solution.