how to keep javascripts after UpdatePanel partial postback

后端 未结 1 353
无人及你
无人及你 2021-01-20 02:05

There is a lot of code so I want to explain the issue shortly in words. I have a Master page, that includes all references to javascript files and have the pages that use th

相关标签:
1条回答
  • 2021-01-20 02:46

    This is because after the partial post back with the Update panel you need to re-initialize the javascript. Here is a general example

    <script type="text/javascript"> 
       // if you use jQuery, you can load them when dom is read.
       $(document).ready(function () {
           var prm = Sys.WebForms.PageRequestManager.getInstance();    
           prm.add_initializeRequest(InitializeRequest);
           prm.add_endRequest(EndRequest);
    
           // Place here the first init
        });        
    
        function InitializeRequest(sender, args) {
        }
    
        function EndRequest(sender, args) {
           // after update occur on UpdatePanel re-init what you need
    
        }
    </script> 
    

    Relative questions:
    Asp.Net UpdatePanel in Gridview Jquery DatePicker
    How to get Id update panel that initial a request in javascript

    After the net 4 you can also simple use the pageLoad function, is similar to the OnLoad function, but is handled by asp.net and is called on the first page load, but also called after each ajax update.

    function pageLoad()
    {
        // init here your javascript
        // This is called when the page load first time
        //  and called again each time you have an Update inside an UpdatePanel
    }
    

    reference: http://msdn.microsoft.com/en-us/library/bb386417(v=vs.100).aspx

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