title: Closing bootstrap modal from server if validation passes
body: <p>Simply stated, I want to have ASP validations fire for my button in my bootstrap modal. If the validations fire, I want them to appear without the modal closing. If the validations don't fire, the modal closes normally.</p>
  
  <p>I've checked out a lot of solutions for this but I don't think I've found one that works quite yet. I want to use ASP validations on one of the text boxes in the bootstrap modal. If I have data-dismiss="modal" on my button, the modal will close even if the validation fires. </p>
  
  <p>In my mind, it would work best if I could close the modal from the server side. But I'm not sure if there are better solutions. Here's my clientside code for the footer:</p>
  
  <pre><code>   &lt;div class="modal-footer"&gt;  
          &lt;asp:Button runat="server" ID="SubmitMessageBtn" Text="Send" class="btn btn-success" OnClick="SubmitMessageBtn_Click" UseSubmitBehavior="false" data-dismiss="modal" /&gt;
          &lt;a href="#" class="btn" data-dismiss="modal"&gt;Close&lt;/a&gt;  
      &lt;/div&gt;  
  </code></pre>
  
  <p>And here's what I've attempted on the server side:</p>
  
  <pre><code> protected void SubmitMessageBtn_Click(object sender, EventArgs e)
      {
          //if validation passes
          if (Page.IsValid)
          {
  
              ClientScript.RegisterStartupScript(GetType(), "Hide", "&lt;script&gt; $('#messageUserModal').modal('hide');&lt;/script&gt;");
          }
      }
  </code></pre>