如何在asp.net中显示警告框
我有一个提交按钮的注册页面。
我希望在“用户点击提交按钮”之后显示一个警告框,之后“用户输入的数据将插入数据库中”。
int i = obj.IU_SubscriberMaster(0, txtFirstname.Text, txtLastname.Text, txtEmail.Text, txtPassword.Text); if (i > 0) { Call ErrorTrap("errormsg"); }
这是我想要显示警报的地方。 我用了
function alerts(str) { return false; }
而不是通过创建一个函数errortrap
public void ErrorTrap(string str) { if (!ClientScript.IsStartupScriptRegistered("alert")) { Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alerts('" + str + "');", true); } }
但它不起作用
有人可以帮忙吗?
常规页面
public void ErrorTrap(string str) { Page.ClientScript.RegisterStartupScript(this.GetType(), "alert" + UniqueID, "alert('" + str + "');", true); }
Ajax页面
如果使用ajax,则需要使用ScriptManager。
public void ErrorTrap(string str) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alert" + UniqueID, "alert('" + str + "');", true); }
alerts
:
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alerts('" + str + "');", true);
需要alert
:
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + str + "');", true);
你的意思是javascript是"alerts("+ str + "');"
而不是"alert(" + str + "');"
?
alerts
应该alert
。 如果您使用的是ajax,请更好地使用ScriptManager。