Friday, August 21, 2009

Call document OnLoad after an AJAX.NET request

When you use your own JavaScript combined with AJAX.NET, you might bump into the problem that your document OnLoad event is not fired after AJAX requests.
This can be solved by using AJAX.NET's endRequest event.
Please note that i use jQuery, so you will need that in order for this example to work.

var documentReady = function() {
// here you do all the stuff you would normally do in $(document).ready()
}

$(document).ready(documentReady);

// This will call the documentReady() function every time an AJAX request is finished
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function() {
documentReady();
});

This can of course be used to call any function after an AJAX request.

2009-08-25: I just found out that you can also use add_pageLoaded() instead of add_endRequest().

/Ruud

No comments:

Post a Comment