title: Multiple Bootstrap Modals and postbacks
body: <p>My knowledge in ASP.NET is very limited, yet, I am building a UI/UX design for an application that will be built in ASP MVC and I've heard rumors of the following problem:</p>
  
  <blockquote>
    <p>When a Boostrap modal fires a button event (onClick), it creates a postback which in turn, it refreshes the page, thus making it impossible for multiple bootstrap modals to work. Unless the modals do not require to interact with the back end, which means they would simply serve a client-side purpose.</p>
  </blockquote>
  
  <p>I need to know how much of this is true and if there is a way to create a search or populate a bootstrap modal with information being entered in a second modal. </p>
  
  <p>Unfortunately, I can't produce a working ASP code but I will produce the HTML portion of it so you have an idea.</p>
  
  <p>Again, my question is, can I populate modal 1 with information entered in modal 2? Modal 2 is invoked from Modal 1. See the code and Demo for details</p>
  
  <pre><code>&lt;div class="container"&gt;
  &lt;h1&gt;Working with Multiple Modals&lt;/h1&gt;
  &lt;div class="margin-lg"&gt;
    &lt;button type="button" class="btn-first-modal btn btn-primary btn-lg" data-toggle="modal" data-target="#first-modal"&gt;
      Launch Modal
    &lt;/button&gt;
  &lt;/div&gt;
  
  
  &lt;div class="modal" id="first-modal" data-backdrop="static" data-keyboard="false"&gt;
    &lt;div class="modal-dialog"&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-header"&gt;
          &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
          &lt;h4 class="modal-title" id="myModalLabel"&gt;First Modal&lt;/h4&gt;
        &lt;/div&gt;
        &lt;div class="modal-body"&gt;
          &lt;div class="row"&gt;
            &lt;div class="col-xs-12 col-sm-4"&gt;
              &lt;label class="label-control"&gt;My ID&lt;/label&gt;
              &lt;input type="text" class="form-control" disabled/&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" class="btn-second-modal within-first-modal btn btn-primary"&gt;
            Add ID
          &lt;/button&gt;
          &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="modal" id="second-modal" data-backdrop="static" data-keyboard="false"&gt;
    &lt;div class="modal-dialog"&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-header"&gt;
          &lt;button type="button" class="btn-second-modal-close close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
          &lt;h4 class="modal-title"&gt;ID Generator&lt;/h4&gt;
        &lt;/div&gt;
        &lt;div class="modal-body"&gt;
          &lt;div class="row"&gt;
            &lt;div class="col-xs-12 col-sm-4"&gt;
              &lt;label class="label-control"&gt;Choose ID&lt;/label&gt;
              &lt;input type="text" class="form-control" /&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" class="btn-second-modal-close btn btn-primary"&gt;Add&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>JS</strong></p>
  
  <pre><code>   var within_first_modal = false;
      $('.btn-second-modal').on('click', function() {
        if ($(this).hasClass('within-first-modal')) {
          within_first_modal = true;
          $('#first-modal').modal('hide');
        }
        $('#second-modal').modal('show');
      });
  
      $('.btn-second-modal-close').on('click', function() {
        $('#second-modal').modal('hide');
        if (within_first_modal) {
          $('#first-modal').modal('show');
          within_first_modal = false;
        }
      });
  
      $('.btn-toggle-fade').on('click', function() {
        if ($('.modal').hasClass('fade')) {
          $('.modal').removeClass('fade');
          $(this).removeClass('btn-success');
        } else {
          $('.modal').addClass('fade');
          $(this).addClass('btn-success');
        }
      });
  </code></pre>
  
  <p><a href="http://codepen.io/LOTUSMS/pen/NxYBwQ" rel="nofollow"><strong>DEMO</strong></a></p>