Call a JavaScript function on ajax complete of update panel

TAGs: 0 Comment

Posted By: eligeske on in

If you’ve ever worked in you have probably ran into update panels (<asp:UpdatePanel></asp:UpdatePanel>) which is microsoft’s way of allowing ajax postbacks to occur for desktop developers. Has anyone seen how much javascript gets produced and the amount of data that gets sent on the post of these things? It’s horrendous, but that’s another post.

My need was to do some validation of returned values inside of the UpdatePanel. Instead of searching through all the magically created JavaScript to figure out what method is doing what or to find the ajax call to do what you need on completion, you can add a hook.

As far as I can see this is available in .net 3.5 and higher, so if you are using something earlier than that, let me know if it works for you. In your .aspx page inside your script tags you would add -Sys.WebForms.PageRequestManager.getInstance().add_endRequest(myJavascriptFunction)

<script type=text/javascript”>
function iAmReallyCool(){
 alert(‘for sure!’);
<asp:UpdatePanel id=”yourid” runat=”server”>
// your stuff in here

So whenever your postback is done .net now knows to run the javascript function iAmReallyCool(). Now if you are going to do anything with the data that is returned from the postback on the page, remember you will have to recall the DOM because the updatePanel is new and is not in memory. If you are using JQuery you would use the .live function.

0 Responses to "Call a JavaScript function on ajax complete of update panel"


Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Learning DHTMLX Suite UI

Learn the foundation of the DHTMLX Suite quickly while building a single page application with multiple components in harmony.

Popular post