[英]Why is my alert not popping up? Asp.net C#
My alert does not pop up. 我的警报没有弹出。 When I debug this with a breakpoint, this line is executed
当我用断点调试它时,执行此行
Response.Write("<script>alert('" + " We don't seem to have this user registered. Please try again " + "') ; location.href='Login.aspx'</script>");
The don't needs to be escaped. 不需要逃脱。
This can be done as follows: 可以按照以下步骤进行:
Response.Write("<script>alert('" + " We don\\'t seem to have this user registered. Please try again " + "') ; location.href='Login.aspx'</script>");
It should pop up now. 它应该现在弹出。
see below code sample to get the alert : 请参阅下面的代码示例以获取警报:
Code Behind : 背后的代码:
protected void Page_Load(object sender, EventArgs e)
{
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "abc", "abc();", true);
}
JavaScript : JavaScript:
function abc(message) {
alert(message + ", I am an alert box!");
}
您也可以尝试一下。
System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Your Message.');", true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.