Friday, May 6, 2011

Handling Javascript Event Binding in Ajaxised Page.

We are using MS ajax to add a function that does the rebinds JS events to the elements.

$(window).load(function () {
 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(RunThisAfterEachAsyncPostback);}
        });
This is the function that executes the rebinding code

 function RunThisAfterEachAsyncPostback(sender, eArgs) {
            try {

                if (eArgs.get_error() == null) {
// Rebinding 
                    $("#btnSaveSubScriptions").button();
                    $("#EventsCheckBoxList tbody td").find('input').click(Events_SubClick);
                }
                else {
                    alert("Error Occurred in the System.Please Contact System Admin");
                    alert(eArgs.get_error());
                }                
                
            }
            catch (err) {
                document.write("There are some errors on this page while loading...<br>" + "RunThisAfterEachAsyncPostback");
                document.write("Error is : " + err.description + " <br>Error number is " + err.number);
            }
        };