How to save javascripts after partial postback of UpdatePanel

There is a lot of code out there, so I want to put it briefly in words. I have a wizard page that includes all links to javascript files and pages that use the master page. I use the refresh bar on my pages and there are some forms inside the refresh bar, including one that has a postback option (i.e. Dropdownlist). The problem is when the state changes and a partial postback occurs, forms that have some capabilities and effects due to these javascripts then lose all functionality. Any help would be appreciated.

+3


source to share


1 answer


This is because after the partial message from the refresh panel, you need to reinitialize the javascript. Here's 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 the ID update panel that triggers a request in javascript



After net 4, you can also just use a function pageLoad

, similar to OnLoad function, but handled by asp.net and called when the first page is loaded, but also called after every 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
}

      

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

+4


source







All Articles