asp.net response.write with bootbox.alert

asp.net response.write with bootbox.alert

本文关键字:bootbox alert with write net response asp      更新时间:2023-09-26

Response.Write("alert(用户名或密码无效(;"(;

从codebehind向用户发出警告。但我想让它看起来更好看。我看到bootbox并添加到库

<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootbox.min.js"></script>

但当我输入错误的信息时,它不会发出任何警报。你能告诉我我哪里做错了吗。谢谢

这个代码我正在使用;(点击按钮,进入"其他"后(

  else
   {
 Response.Write("<script type=text/javascript>bootbox.alert(Username or password invalid);</script>");
   }

您没有在JavaScript中引用字符串。看看你向页面发射的是什么:

Response.Write("<script type=text/javascript>bootbox.alert(Username or password invalid);</script>");

这将导致:

<script type=text/javascript>bootbox.alert(Username or password invalid);</script>

浏览器将可能为您更正未引用的type属性,但JavaScript不会为您更正已引用的字符串。您的JavaScript控制台可能显示了一个未定义Username或类似性质的错误。

因此,首先你需要正确地引用字符串:

Response.Write("<script type='"text/javascript'">bootbox.alert('Username or password invalid');</script>");

现在,除此之外,实际上不应该使用Response.Write()向页面发送值。它无法控制在页面上的位置,这可能很重要。将RegisterStartupScript作为一种替代方案。这将在页面中更合适的位置包含客户端代码。