【发布时间】:2021-01-31 22:34:02
【问题描述】:
我在从服务器端 ASP.NET 代码打开模式引导窗口时遇到问题,尽管我遵循了我在此处找到的所有示例。代码执行,我没有收到任何 JavaScript 错误,但模式窗口从未出现。
这里是模态窗口 HTML:
<div id="StatusPopUp" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
×</button>
<h4 class="modal-title">Credentials Not Found</h4>
</div>
<div class="modal-body">
<p class="text-justify">
The email address and/or password entered do not match our records. Please try your login again if you believe this is an
error.
</p>
<p class="text-justify">
If you are an associate and need credentials for use of the Portal then please contact your regional office
or Team Sales Lead to request them.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">
Close</button>
</div>
</div>
</div>
</div>
这是打开模态的Javascript代码:
<script type="text/javascript">
function Show() {
$("#StatusPopUp").modal("show");
}
</script>
最后,这是用于打开模式的服务器端代码:
protected void btnGo_Click(object sender, EventArgs e) {
bool isValid=Membership.ValidateUser(UName.Value,Pwd.Value);
if ( isValid )
this.Response.Redirect ( "associates/home.aspx", true );
else
ClientScript.RegisterStartupScript ( this.GetType ( ), "alert", "Show();", true );
}
目标是当用户尝试在登录页面上登录但未成功时,模态框应弹出一条消息。正如我所说,所有的代码都按照编写的方式执行,但它仍然没有让模态窗口真正出现在浏览器中。帮忙?
【问题讨论】:
-
您检查控制台是否有错误?如果有,它们是什么?
-
浏览器控制台或 .NET 端没有任何类型的错误。这是某种“无声的失败”,这是令人困惑的部分。
-
在加载引导 js 库之前,您的 RegisterStartUp 脚本可能正在运行(但在这种情况下,我预计会出现控制台错误)。在 show 方法的开头添加
console.log($("#StatusPopUp")),以确保在该点加载模态元素。我假设这是一个网络表单项目是否正确?
标签: asp.net twitter-bootstrap server-side-scripting