Firing JavaScript functions after a .Net AJAX request

I wanted to have a function called after data was returned to the page from a .Net AJAX call. (The idea was to fade out when you pressed “submit” and then redraw when data came back.) It turns out there are handy handlers already there to, erm, handle this:

Sys.WebForms.PageRequestManager.getInstance()
.add_beginRequest(StartRequestHandler);
Sys.WebForms.PageRequestManager.getInstance()
.add_endRequest(EndRequestHandler);

Those little nuggets add calls to your functions, and the functions themselves are:

function StartRequestHandler(sender,args)
{
}
function EndRequestHandler(sender, args)
{
}

Nice.

Leave a Reply

Your email address will not be published. Required fields are marked *