Document.Ready() is not working after PostBack

前端 未结 8 1845
天命终不由人
天命终不由人 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 19:20

    This is an example that worked for me in the past:

    <script>
    function MyFunction(){ 
        $("#id").text("TESTING");
    }
    //Calling MyFunction when document is ready (Page loaded first time)
    $(document).ready(MyFunction); 
    
    //Calling MyFunction when the page is doing postback (asp.net)
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(MyFunction);
    </script>
    
    0 讨论(0)
  • 2020-12-02 19:22

    I was also facing the same problem but i found the jQuery $(document).ready event handler works when page loads, but after ASP.Net AJAX UpdatePanel Partial PostBack it does not get called. so use Sys.Application.add_load(function(){}); instead of $(document).ready. This works perfectly for me :)

    <script>
    Sys.Application.add_load(function() { //Your code }); </script>

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