客户端脚本不会执行的ScriptManager [英] Client side script won't execute with ScriptManager

查看:79
本文介绍了客户端脚本不会执行的ScriptManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我有有一个用户控件
    更新面板

  2. 我试图执行一个客户端
    从一个异步回发的脚本
    在UpdatePanel内按钮

  3. 我使用
    ScriptManager.RegisterStartupScript
    永远不会执行该脚本,但它
    被执行

  4. 使用ScriptManager代理不是
    用户控件本身里面是
    在包含用户的页面
    控制

  5. 有没有办法解决这问题?

脚本注册:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆