Rebinding events in jQuery after Ajax update (updatepanel)

后端 未结 9 2087
悲哀的现实
悲哀的现实 2020-11-27 10:15

I have several input and option elements on my page, each (well almost) have an event attached to update some text on the page once they change. I use jQuery which is really

相关标签:
9条回答
  • 2020-11-27 10:51

             <script type="text/javascript">
                 function pageLoad() {
    
                     if (Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) {
    
    
           }
    
                </script>
    
            </ContentTemplate>
        </asp:UpdatePanel>
    

    into of the "if" you can put the code that you need execute every time that the updatepanel does AsyncPostBack.

    0 讨论(0)
  • 2020-11-27 10:54

    As of jQuery 1.7, the recommended way to do this is to use jQuery's .on() syntax.

    Make sure, however, that you set up the event on the document object, not the DOM object itself. For example, this will break after the UpdatePanel postback:

    $(':input').on('change', function() {...});
    

    ... because the ':inputs' have been rewritten. Do this instead:

    $(document).on('change', ':input', function() {...});
    

    As long as the document is around, any inputs (including those from UpdatePanel refreshes) will trigger the change handler.

    0 讨论(0)
  • 2020-11-27 10:59

    Or you could check the latest jQuery's live functionality via the on() method.

    0 讨论(0)
提交回复
热议问题