After Post Back my jQuery code not working

前端 未结 2 938
礼貌的吻别
礼貌的吻别 2020-12-19 18:50

I have server side button. First time jquery is working fine but next time jQuery not wroking. I am using jQuery inside Update Panel.

Below is my Jquery code.

相关标签:
2条回答
  • 2020-12-19 18:58

    Your initialization will run only on document ready (not on postback). Since you place your control inside UpdatePanel, anything will updated after postback.

    Try with the below suggestion

    You need to recreate the Jquery Codes on postbacks like given below

    <script type="text/javascript"> 
        $(document).ready(function() {
            //jquery code
        });
    
        var parameter = Sys.WebForms.PageRequestManager.getInstance();
    
        parameter.add_endRequest(function() {
            //jquery code again for working after postback
        });
    </script>
    

    this is the solution got once i got the same issue and worked fine for me..check

    Updated:

    If above code give error like Sys undefined then try below code.

    <script type="text/javascript"> 
    
    $(document).ready(function () {
    
        //jquery code
    
        var parameter = Sys.WebForms.PageRequestManager.getInstance();
    
        parameter.add_endRequest(function () {
            //jquery code again for working after postback
        });
    });
    
    </script>
    
    0 讨论(0)
  • 2020-12-19 19:12

    Change it from:

    $('.ClassName').click(function(e) {
    /////
    });
    

    to:

    $(document).on("click", ".ClassName", function (e) {
    /////
    });
    
    0 讨论(0)
提交回复
热议问题