ASP.NET postback with jQuery? ASP.NET postback with jQuery? asp.net asp.net

ASP.NET postback with jQuery?


See if this helps: http://www.codeproject.com/KB/aspnet/sample.aspx.

Basically, you declare a dummy anchor tag:

<a id="anchorId" runat="server" onclick="return true" onserverclick="foo"></a> 

In your code behind, you need to declare a foo method:

protected void foo(object sender, EventArgs e){    // Do something here}

Then you can invoke this anchor's onclick function with this javascript:

document.getElementById('anchorId').click()


While you can do Postbacks with JQuery, it might be better to call a web method (web service that is in your page). The call could also be faster because you are not posting the entire page ViewState.


You need to set the __EVENTTARGET hidden field to an appropriate value if you want to trigger the event handler on postback. I would do it a different way, however. Put ASP buttons in your modal dialog that have the event handler associated with them. Have the click handler that pops up the dialog return false (so that the postback doesn't happen from that button click). This way your form is posted back from an ASP button and the handler, including the client-side hidden field setting, is invoked automatically.