cem
cem

Reputation:

Using doPostBack Function in asp.net

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()
       }

Upvotes: 5

Views: 6502

Answers (4)

cem
cem

Reputation:

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?

Upvotes: 0

tsilb
tsilb

Reputation: 8037

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

Upvotes: 0

Canavar
Canavar

Reputation: 48088

Try this :

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

Upvotes: 1

Sergio
Sergio

Reputation: 8259

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

Upvotes: 1

Related Questions