Tuesday, February 26, 2013

jQuery with AJAX UpdatePanel

We have certain sections of ASPX which are inside an UpdatePanel, so that partial updating happens on button click events. We also have some enable/disable capability of those buttons using some other checkboxes and this happens through checkboxes.
We had jQuery working fine earlier and now with introducing UpdatePanels, jQuery does not work. The reason is that when a partial udpate happens the UpdatePanel overwrite the html including the buttons inside the UpdatePanel. So two things we could do. Either have the jQuery function run on every page load or, update the jQuery when a AJAX request ends.
Here is the code I put in script block (fcourse this is in a SharePoint site page)

    var requestManager = Sys.WebForms.PageRequestManager.getInstance();
    requestManager.add_endRequest(function(){....});


So whatever functions we put inside add_endRequest() are refired at the end of AJAX partial request. NOTE: Even if you dont see Visual Studio not finding the intellisense for this piece of java script, its ok because as long as there is an UpdatePanel on the page, this code works.

No comments:

Post a Comment