【问题标题】:Script manager popup doesn't appear脚本管理器弹出窗口不出现
【发布时间】:2014-06-19 20:22:07
【问题描述】:

我有一个 ASP.NET 页面。我想在点击页面上的某个按钮时弹出一个弹出窗口。我使用的语法是这样的:

ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Invalid Address!!');", true);

弹出窗口没有出现。

但是,当在同一个项目的不同页面上尝试相同的语法时,它起作用了。

有什么想法吗?

【问题讨论】:

  • 也许您只是出于测试目的而尝试这样做。但根据我的经验,JavaScript alert 对话框非常难看,应该避免使用 ModalPopupExtenderjQuery UI DialogBootstrap Modal or Dialog 等。
  • 你是对的,它真的很难看,但我只需要简单的错误 massegeBox 就足够了。我不明白为什么它不能在这个页面上工作。
  • 那么您是否在某些验证失败后在后面的代码中抛出警报?或者,如果当您单击按钮时立即弹出警报,那么您可以在标记本身为按钮编写“onclick”事件。
  • 是的,在 DeleteMethod of listView 内部的代码中某些验证失败后,我会发出警报,即在 updatePanel 中(也许这是问题的原因?)

标签: c# asp.net popup


【解决方案1】:

尝试从

更改以下行
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Invalid Address!!');", true);

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "popup", "alert('Invalid Address!!');", true);

如果上面的代码不管什么原因都不起作用,试试下面的代码是否有效

 ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert",
                            "Javascript:displayAlert('Invalid Address!!');", true);

还有你的 JS 函数

function displayAlert(msg) {
   alert(msg);
   return false;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    • 2022-01-18
    • 2022-06-11
    相关资源
    最近更新 更多