How to have a javascript callback executed after an update panel postback?

后端 未结 5 1536
攒了一身酷
攒了一身酷 2020-11-27 11:52

I\'m using a jQuery tip plugin to show help tips when the user hovers certain elements of the page.

I need to register the plugin events after the page is loaded usi

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 12:03

    If you want to do specific operations before and after the UpdatePanel has loaded, you can override BeginPostbackRequest and EndPostbackRequest like so:

    var postbackControl = null;
    var updatePanels = null;
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_beginRequest(BeginPostbackRequest);
    prm.add_endRequest(EndPostbackRequest);
    
    function BeginPostbackRequest(sender, args) {
        prm._scrollPosition = null;
        postbackControl = args.get_postBackElement();
        postbackControl.disabled = true;
        updatePanels = args._updatePanelsToUpdate;
        // do your stuff
    }
    
    function EndPostbackRequest(sender, args) {
        // do your stuff
        postbackControl.disabled = false;
        postbackControl = null;
        updatePanels = null;
    }
    

    This is very handy if you want to process only HTML that was delivered by the update panel. Some operations require more resources and it would be overkill to process the whole DOM tree on pageLoad.

提交回复
热议问题