c# - Javascript 警报不显示

标签 c# javascript asp.net

无法从我后面的代码中显示 javascript 警报。

c# - 点击按钮

if (response != "")
{
    ClientScript.RegisterStartupScript(typeof(Page), "AlertPopup", "<script type='text/javascript'>alert('Day already exists, please edit the existing day');</script>");
    return; 
}

这来自 UpdatePanel。我不确定这是否有所作为。

编辑

改成这段代码,还是不行:

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "AlertPopup", "<script type='text/javascript'>alert('Day already exists, please edit the existing day');</script>", true);

解决方案

它加载了太多的脚本标签,这段代码解决了这个问题:

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "AlertPopup", "alert('Day already exists, please edit the existing day');", true);

最佳答案

由于它来自 UpdatePanel,请尝试使用 ScriptManager.RegisterStartupScript 静态方法。

HTH.

关于c# - Javascript 警报不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6227743/

相关文章:

javascript - 如何在页面加载和自动点击时获取警报消息内容

c# - 多个约束泛型类型的字典和接口(interface)

c# - 使用语义内核(ChatGPT)的浏览技巧

javascript - Jquery jquery.sumoselect

javascript - NodeJS - socket.on 似乎没有被调用

javascript - VeeValidate 不验证来自动态表单的输入

ASP.NET Web API 私有(private) Controller

asp.net - 如何迭代DataTable中给定行中的所有项目

c# - 从字符串中剥离所有 HTML?

c# - 如何在 Xamarin(iOS 和 Android)应用程序中使用 Windows 命名空间?