Why does my function run several times after downloading UpdatePanel

So, I want to run some javaScript function after updating my updated panel, so I have:

function pageLoad() { 

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(panelLoaded);
}


function panelLoaded(sender, args) {
        alert("foobar");
}

With the above code, if I update the panel once, "foobar" will be warned once; If I update the panel a second time, "foobar" will appear twice; the third time I run the panel to update, "foobar" popped up three times ... 4th time pop 4 times so on and so on ....

What caused this?

Thanks ~~~

+5
source share
3 answers

, , , , prm, . Sys.WebForms.PageRequestManager.getInstance(). Remove_pageLoaded (panelLoaded); (), .

+1

, pageLoad postbacks . :

function pageLoad(sender, eventArgs) {
    // If this is being executed by ajax
    if (eventArgs) {
        // And this is only a partial load
        if (eventArgs.get_isPartialLoad()) {
            // Don't perform any further processing
            return;
        }
    }
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(panelLoaded);
}
+3

, . pageLoad Application.Init PageRequestManager.EndRequest. , ( DOM Ready) Partial PostBack

, pageLoad PostBacks; .

pageLoaded ScriptManager .

0
source

All Articles