Javascript警报未显示

时间:2011-06-03 13:31:05

标签: 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);

1 个答案:

答案 0 :(得分:3)

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

HTH。