Friday, November 1, 2013

jQuery not firing after Microsoft AJAX Update Panel Postback - or why pageload is better than document.ready

I ran into an interesting issue today while using jQuery in an AJAX Panel.  It appears that existing items that were there on original page load were triggering but any new ones after an ajax postback were not.  I did some searching and came across the issue.

It appears that document ready and pageload are not the same  document.ready only loads once when the page is loaded but not on all the AJAX page loads.  The solution is to use function pageLoad() and do your calls within there.

However, this leads to another problem.  If you simply use function pageLoad() then you can only call it once on your page.  There is a solution to this as well.  This article explains how to make ASP.NET AJAX Multiple pageload functions possible through simply using

<script type="text/javascript">

    Sys.Application.add_load(function () {
     // Your Code here
   }

</script>

If you have any tips, tricks or resources you would like to share with the guild please email them to me at chris.williams@threepointturn.com


No comments:

Post a Comment