[英]How to call a javascript function after an async postback
I was using the following script to call a javascript function only if my page in Edit Mode: 仅当我的页面处于“编辑模式”时,我才使用以下脚本调用javascript函数:
protected void Page_PreRender(object sender, EventArgs e)
{
if (EditMode)
ClientScript.RegisterStartupScript("".GetType(),
"EnableSelectableKey",
"EnableSelectableForRolesLists();",
true);
}
After I added an update panel, the script has not been called. 添加更新面板后,脚本尚未被调用。
How to fix the problem? 如何解决问题?
Using Sys.WebForms.PageRequestManager.endRequest
as Dave_Stott says is a cleaner way to do this (if there is such a thing as "clean" when talking about UpdatePanels
and client/server interaction). 如Dave_Stott所说,使用
Sys.WebForms.PageRequestManager.endRequest
是一种更干净的方法(如果在谈论UpdatePanels
和客户端/服务器交互时存在“干净”的情况)。 But you can also simply change your code to use ScriptManager
instead of ClientScript
and it should work: 但是您也可以简单地将代码更改为使用
ScriptManager
而不是ClientScript
,它应该可以工作:
ScriptManager.RegisterStartupScript("".GetType(),
"EnableSelectableKey",
"EnableSelectableForRolesLists();",
true);
Have a look at: http://msdn.microsoft.com/en-us/library/bb383810.aspx 看看: http : //msdn.microsoft.com/en-us/library/bb383810.aspx
This should point you in the right direction :) 这应该为您指明正确的方向:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.