客户端脚本不会执行的ScriptManager [英] Client side script won't execute with ScriptManager
问题描述
- 我有有一个用户控件
更新面板 - 我试图执行一个客户端
从一个异步回发的脚本
在UpdatePanel内按钮 - 我使用
ScriptManager.RegisterStartupScript
永远不会执行该脚本,但它
被执行 - 使用ScriptManager代理不是
用户控件本身里面是
在包含用户的页面
控制 - 有没有办法解决这问题?
脚本注册:
ScriptManager.RegisterStartupScript(
this,
this.GetType(),
"CloseEdit",
"CloseEditModal();",
true
);
谢谢,达米恩。
推荐答案
的文档到的 ScriptManager.RegisterStartupScript方法(控制,类型,字符串,字符串,布尔值)
(我假设你用这个重载)说:
The documentation to the ScriptManager.RegisterStartupScript Method (Control, Type, String, String, Boolean)
(I assume you use this overload) says:
这是启动脚本块
通过使用此方法是注册
发送到页仅当控制
即注册块
这是一个的UpdatePanel
控件内
正在更新。
Startup script blocks that are registered by using this method are sent to the page only when the control that is registering the block is inside an
UpdatePanel
control that is being updated.
我假设你从你的用户控件调用 ScriptManager.RegisterStartupScript
方法(其中有一个更新面板的 的像你说的)。这意味着该方法的第一个参数的不是的UpdatePanel
控制正在更新的里面,所以脚本块未注册。因此,改变你的脚本registraction为:
I assume you call the ScriptManager.RegisterStartupScript
method from your user control (which has an update panel as you said). This means the first parameter of the method is not inside an UpdatePanel
control that is being updated, so the script block is not registered. So changing your script registraction to:
ScriptManager.RegisterStartupScript(
btnUpdate,
btnUpdate.GetType(),
"CloseEdit",
"CloseEditModal();",
true
);
应该解决您的问题。 btnUpdate
这里是你内心的按钮的UpdatePanel
引起回发(你在第2段提到这一点)。
should solve your problem. btnUpdate
here is the button inside you UpdatePanel
that caused the postback (you mention this in paragraph 2).
这篇关于客户端脚本不会执行的ScriptManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!