如何在异步回发后调用 javascript 函数

Hom*_*mam 0 c# asp.net updatepanel

仅当我的页面处于编辑模式时,我才使用以下脚本调用 javascript 函数:

protected void Page_PreRender(object sender, EventArgs e)
{
    if (EditMode)
        ClientScript.RegisterStartupScript("".GetType(), 
                                           "EnableSelectableKey", 
                                           "EnableSelectableForRolesLists();",
                                            true);
}
Run Code Online (Sandbox Code Playgroud)

我添加了更新面板后,脚本没有被调用。

如何解决问题?

Jam*_*rgy 5

使用Sys.WebForms.PageRequestManager.endRequestDave_Stott 所说的是一种更简洁的方法来做到这一点(如果在谈论UpdatePanels客户端/服务器交互时有“干净”这样的东西)。但是您也可以简单地更改您的代码以使用ScriptManager而不是ClientScript它应该可以工作:

ScriptManager.RegisterStartupScript("".GetType(), 
                                           "EnableSelectableKey", 
                                           "EnableSelectableForRolesLists();",
                                            true);
Run Code Online (Sandbox Code Playgroud)