尽管遵循了我在此处找到的所有示例,但在从服务器端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 );
}
目的是当用户尝试在登录页面上登录但未成功时,该模式应弹出并显示一条消息。就像我说的那样,所有代码都是按编写的方式执行的,但是它仍然不允许模态窗口真正出现在浏览器中。救命?
如果模态的显示仅是由页面重新加载时的服务器端响应触发的,那么我将使用asp:panel
并将JavaScript移至常规jquery$(document).ready()
函数中进行一些重构。
这样,模态HTML甚至直到需要时才呈现,并且您可以更好地控制何时调用显示模态的脚本。您不必麻烦任何外部脚本加载等。
aspx
<asp:panel id="pnlStatusPopUp" runat="server" visible="false">
<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>
</asp:panel>
.cs
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
pnlStatusPopUp.visible = true;
}
js
$(document).ready(function(){
$("#StatusPopUp").modal("show");
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句