How to execute javascript once an update panel refreshes (Can't get Sys.WebForms.PageRequestManager.getInstance().add_endRequest(); to work)

微笑、不失礼 提交于 2019-12-07 08:40:48

问题


I'm trying to run javascript once an update panel has refreshed. I've read a few places that you can use code similar to this:

function codeToRun() {
    //Code Here
}

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(codeToRun);

But it doesn't seem to be working... any ideas? I've tried putting the code inside the Content area of the update panel as well as outside of it... haven't had any luck so far. Please let me know if you have any insight to why this might be happening.

Thanks,
Matt


回答1:


Everything needs to be outside of the UpdatePanel:

Markup:

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

Script:

if( typeof(Sys) != "undefined" )
{
    Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initRequestHandler);     
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);   
}
else
{
    //we have a problem with ScriptManager
}



回答2:


The call to System.WebForms.PageRequestManager should come after the library has been included and initialized, but probably not inside the UpdatePanel.



来源:https://stackoverflow.com/questions/1626515/how-to-execute-javascript-once-an-update-panel-refreshes-cant-get-sys-webforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!