5

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()
 }
santosh singh
28.8k27 gold badges88 silver badges134 bronze badges
asked Feb 4, 2009 at 13:30

4 Answers 4

1

Try this :

System.Web.UI.HtmlControls.HtmlAnchor myAnchor = new System.Web.UI.HtmlControls.HtmlAnchor();
string postbackRef = Page.GetPostBackEventReference(myAnchor);
myAnchor.HRef = postbackRef;
answered Feb 4, 2009 at 13:45
Sign up to request clarification or add additional context in comments.

1 Comment

I've got few questions: 1)Does System.Web.UI.HtmlControls.HtmlAnchor myAnchor equals to <a runat="server" ID="myAnchor" /> in aspx ? 2) Does: Page.GetPostBackEventReference(myAnchor) is equal to <a href="__doPostBack('myAnchor.ClientID','')" /> in client browser?
1

__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.

answered Feb 4, 2009 at 13:35

Comments

0

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

answered Feb 4, 2009 at 13:52

Comments

0

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?

answered Feb 4, 2009 at 13:53

5 Comments

Are you using Update panel or something like that ? What you mean by posting only datagrid ?
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.
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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.