Performing async postback from javascript
UpdatePanels are a great way to update portions of a webpage. They only have one "problem": they need a control to fire the async postback. When you are performing a postback from javascript using the following code:
__doPostBack( 'EventName' , 'EventArgs');
the execution will always be synchronous. You can work around this by using a hidden control and fire one of its events, but this is not always the most flexible solution. I debugged the framework javascript a little and found another way to do it, completely
in javascript. It's done by adding the eventtargetname into two arrays of the PageRequestManager. I have created a javascript function that handles this for me:
function doPostBackAsync( eventName, eventArgs )
{
var prm = Sys.WebForms.PageRequestManager.getInstance();
if ( !Array.contains( prm._asyncPostBackControlIDs, eventName) )
{
prm._asyncPostBackControlIDs.push(eventName);
}
if ( !Array.contains( prm._asyncPostBackControlClientIDs, eventName) )
{
prm._asyncPostBackControlClientIDs.push(eventName);
}
__doPostBack( eventName, eventArgs );
}
You can call it just like the original __doPostBack function.