Document.Ready() is not working after PostBack

前端 未结 8 1846
天命终不由人
天命终不由人 2020-12-02 18:39

I have a page that contains a user control within an update panel. $(document).ready(function() ) { is called and executes the code correctly when the page firs

8条回答
  •  天命终不由人
    2020-12-02 18:59

    I've run into this a while ago, as El Ronnoco said, it has to go with the DOM not being reloaded. However you can simply change $(document).ready(function() { to

    Sys.Application.add_load(function() {
    

    This will force it to run on every postback.

    You can use function pageLoad() as well, but you can only have one pageLoad function, whereas with Sys.Application.add_load, you can add as many handlers as you wish.

提交回复
热议问题