我尝试在互联网上搜索在asp.net中显示javascript警告框的方法,但没有一个工作。 我的代码:
string message;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
if ((int) Application["taken"] == 1)
{
message = "Username and email already in use!";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Username and email already in use!')", true);
}
else if ((int) Application["taken"] == 2)
{
message = "Username already in use!";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Username already in use!')", true);
}
else if ((int) Application["taken"] == 3)
{
message = "Email already in use!";
sb.Append("<script type = 'text/javascript'> window.onload=function(){alert('" + message + "')} </script>");
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());
}
我需要做什么?
答案 0 :(得分:0)
你能试试RegisterStartupScript
吗?
ClientScript.RegisterStartupScript(this.GetType(), "alertMessage", "alert('Username already in use!')", true);
答案 1 :(得分:0)
您不能两次调用脚本,而是在同一脚本中两次编写警报代码。 您可以在aspx页面上编写javascript方法,也可以在javascript文件中编写并包含它。然后在cs页面注册为
ScriptManager.RegisterStartupScript(this, this.GetType(), “ShowStatus”, “javascript:ShowMessages(‘First Message’,’Second Message’);”, true);
function ShowMessages(msg1, msg2) {
alert(msg1);
alert(msg2);
}
详情请点击link