jquery needs to rebind events on partial page postback

后端 未结 5 1880
别那么骄傲
别那么骄傲 2021-01-05 00:47

How can I rebind my events (jquery) when I perform a partial page postback?

I am wiring everything up using:

$(document).ready(function(){};
<         


        
5条回答
  •  情深已故
    2021-01-05 01:23

    You can either tap into the PageRequestManager endRequestEvent:

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

    Or if it is control events you're trying to attach, you can use jQuery live events.

    Another option is to do the event delegation manually. It is what the "live" event are doing under the covers. Attach the event handler to the document itself, then conditionally execute your method if the sender of the event was element you expect.

    $(document).click(function(e){  
        if($(e.target).is(".collapseButton")){  
            $(this).find(".collapsePanel").slideToggle(500);  
        }  
    })  
    

提交回复
热议问题