ASP.NET – UpdatePanel and JavaScript

asp.netasp.net-ajaxupdatepanel

Is there a way to execute script when an UpdatePanel process is finished.

I have a page that allows "inserting", "copying", and "editing" of a record.
This is all done on an UpdatePanel to prevent a page navigation.
Somewhere else on the page I would like to print a "flash" message – like "You have successfully entered a record." It is not near the UpdatePanel and I'd like to use a jQuery effect on the message so it fades out after 4 seconds. How can I send script back with the UpdatePanel or have it execute after a UpdatePanel refresh? Should I write script to an asp:literal? thoughts?

Best Answer

Yes:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);

And then:

function endRequestHandler(sender, args)
{
  // Do stuff
}

Documentation here and here. Keep in mind that this will fire for every AJAX request on the page.

Related Topic