ASP.NET postback via JQuery / Javascript
ASP.NET Webforms isn’t the best platform to build web applications. I can’t wait to migrate my apps to ASP.NET MVC but until i have the time to do that i have to coup with some of asp.net strange parts.
Today i wanted to invoke a postback via JQuery wich actually was fairly easy but i wanted to write a small post about it.
The trick was to get the Javascript that asp.net call to do a postback, save it somewhere and then executed via the eval() method. I used a hidden form to store the postback script.
In the asp.net file
hdnSearchPostBack.Value = Page.ClientScript.GetPostBackEventReference(SearchButton, string.Empty);
In the js file
function() { eval($("#ctl00_ctl00_hdnSearchPostBack").val()); }
Simple as that!