0

I can display a Modal when using an ASP.Net button (while using the solution given here: Display Bootstrap Modal from Asp.Net Webforms) My problem is that the Modal doesn't display when I add ASP.Net Validation to the form. Any idea why this might be? This is the 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">
                                &times;</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>

This is one of the Validation blocks:

<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>

And here is the button:

<div class="form-group">
  <asp:Button class="btn btn-success" ID="btnInsert" runat="server" CausesValidation="True" Text="Insert Choice" ValidationGroup="Choice" />
</div>

And here is the 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
Community
  • 1
  • 1
Dec
  • 15
  • 8
  • some errors in dev console? – demo Aug 21 '15 at 11:29
  • @demo I'm not sure what you mean? I've taken out some code for clarity in the btnInsert code. Basically, this code inserts some data to a database and, if successful, displays the modal popup: except it doesn't. Before I added the Validation to the fields, the modal popup displayed properly. – Dec Aug 21 '15 at 12:07
  • if you open your application in browser, open Developer Console (basically just click F12) - goto Console - and check if there are some errors – demo Aug 21 '15 at 12:09

0 Answers0