C# 如何在asp.net中显示警报框

C# 如何在asp.net中显示警报框,c#,asp.net,C#,Asp.net,我有一个带有提交按钮的注册页面 我想在“用户点击提交按钮”时显示一个警告框,之后“用户输入的数据被插入数据库” 这是我要显示警报的地方。 我曾经 而不是通过创建函数errortrap public void ErrorTrap(string str) { if (!ClientScript.IsStartupScriptRegistered("alert")) { Page.ClientScript.RegisterStartupScript(this.GetTy

我有一个带有提交按钮的注册页面

我想在“用户点击提交按钮”时显示一个警告框,之后“用户输入的数据被插入数据库”

这是我要显示警报的地方。 我曾经

而不是通过创建函数errortrap

public void ErrorTrap(string str)
{
    if (!ClientScript.IsStartupScriptRegistered("alert"))
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alerts('" + str + "');", true);
    }
}
但它不起作用

有人能帮忙吗?

警报

Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alerts('" + str + "');", true);
需要发出
警报

 Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + str + "');", true);

您的意思是让javascript成为
“警报(“+str+”);“
而不是
”警报(“+str+”);“
”?

常规页面吗 Ajax页面 如果使用ajax,则需要使用ScriptManager

public void ErrorTrap(string str)
{
   ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alert" + UniqueID, 
      "alert('" + str + "');", true);
}

警报
应为
警报
。如果您使用的是ajax,最好使用ScriptManager。

当我运行“常规页面”时,我注意到警报发生在我在菜单项上定位css之前
 Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + str + "');", true);
public void ErrorTrap(string str)
{
   Page.ClientScript.RegisterStartupScript(this.GetType(), "alert" + UniqueID, 
     "alert('" + str + "');", true);
}
public void ErrorTrap(string str)
{
   ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alert" + UniqueID, 
      "alert('" + str + "');", true);
}