我可以在使用ASP.Net按钮时显示模态(使用此处给出的解决方案:Display Bootstrap Modal from Asp.Net Webforms) 我的问题是,当我将ASP.Net Validation添加到表单时,Modal不会显示。知道为什么会这样吗? 这是模态:
<!-- Success Modal -->
<div class="modal fade" id="modSuccess" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<asp:UpdatePanel ID="upModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×</button>
<h4 class="modal-title">
<asp:Label ID="lModalTitle" runat="server" Text=""></asp:Label></h4>
</div>
<div class="modal-body">
<asp:Label ID="lModalBody" runat="server" Text=""></asp:Label>
</div>
<div class="modal-footer">
<button class="btn btn-info" data-dismiss="modal" aria-hidden="true">
Close</button>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
&#13;
这是验证块之一:
<div class="form-group">
<label>
Year of Birth*</label>
<asp:TextBox class="form-control" ID="tYOB" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvYOB" runat="server" ControlToValidate="tYOB" Display="None" ErrorMessage="Year of Birth is required" ValidationGroup="Choice"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="rfvYOBValidatorCalloutExtender" runat="server" TargetControlID="rfvYOB" Enabled="True">
</asp:ValidatorCalloutExtender>
<asp:RegularExpressionValidator ID="revYOB" runat="server" ControlToValidate="tYOB" Display="None" ErrorMessage="Year of Birth must be a 4 digit Year" ValidationExpression="^\d{4}$" ValidationGroup="Choice"></asp:RegularExpressionValidator>
<asp:ValidatorCalloutExtender ID="revYOB_ValidatorCalloutExtender" runat="server" TargetControlID="revYOB" Enabled="True">
</asp:ValidatorCalloutExtender>
</div>
&#13;
这是按钮:
<div class="form-group">
<asp:Button class="btn btn-success" ID="btnInsert" runat="server" CausesValidation="True" Text="Insert Choice" ValidationGroup="Choice" />
</div>
&#13;
这是CodeBehind:
Protected Sub btnInsert_Click(sender As Object, e As System.EventArgs) Handles btnInsert.Click
'This inserts the Choice
Try
With CInfo
'More code here
.insert()
End With
lModalTitle.Text = "Choice Entered"
lModalBody.Text = tChoice.Text & " has been successfully entered"
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "modSuccess", "$('#modSuccess').modal();", True)
upModal.Update()
Catch ex As Exception
'Catch Code
End Try
End Sub