title: Bootstrap modal's button ASP.NET C#
body: <p>I have a problem with my site</p>
  
  <p>I have this modal:</p>
  
  <pre><code>    &lt;div class="modal fade " id="loginModal" tabindex="-1" role="dialog" aria-labelledby="loginModalLabel" aria-hidden="true"&gt;
          &lt;div class="modal-dialog"&gt;
              &lt;div class="modal-content login-modal"&gt;
                  &lt;div class="modal-header login-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 text-center" id="loginModalLabel"&gt;Autenticazione utente&lt;/h4&gt;
                  &lt;/div&gt;
                  &lt;div class="modal-body"&gt;
                      &lt;div class="text-center"&gt;
                          &lt;div class="form-group"&gt;
                              &lt;asp:Panel ID="pError" Visible="false" runat="server"&gt;
                                  &lt;div class="alert alert-dismissable alert-danger" id="confirm" runat="server"&gt;
                                      &lt;asp:Label ID="lblError" runat="server"&gt; &lt;/asp:Label&gt;
                                      &lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                                  &lt;/div&gt;
                              &lt;/asp:Panel&gt;
                          &lt;/div&gt;
                          &lt;div role="tabpanel" id="pnl" class="login-tab"&gt;
                              &lt;!-- SCHEDE --&gt;
                              &lt;ul class="nav nav-tabs" role="tablist"&gt;
                                  &lt;li role="presentation" class="active"&gt;&lt;a id="signin-taba" href="#home"  aria-controls="home" role="tab" data-toggle="tab"&gt;Accedi&lt;/a&gt;&lt;/li&gt;
                                  &lt;li role="presentation"&gt;&lt;a id="signup-taba" href="#profile"  aria-controls="profile" role="tab" data-toggle="tab"&gt;Registrati&lt;/a&gt;&lt;/li&gt;
                                  &lt;li role="presentation"&gt;&lt;a id="forgetpass-taba" href="#forget_password" aria-controls="forget_password" role="tab"  data-toggle="tab"&gt;Recupero&lt;/a&gt;&lt;/li&gt;
                              &lt;/ul&gt;
  
                              &lt;!-- LOGIN --&gt;
  
  
                              &lt;div class="tab-content"&gt;
                                  &lt;div role="tabpanel"  class="tab-pane active text-center"  id="home"&gt;
  
                                      &lt;div class="clearfix"&gt;&lt;/div&gt;
                                      &lt;%-- email --%&gt;
                                      &lt;div class="form-group"&gt;
                                          &lt;div class="input-group"&gt;
                                              &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-at"&gt;&lt;/i&gt;&lt;/div&gt;
                                              &lt;asp:TextBox ID="txtLoginEmail"  CssClass="form-control" placeholder="Email" runat="server"&gt;&lt;/asp:TextBox&gt;
  
                                          &lt;/div&gt;
                                          &lt;asp:RequiredFieldValidator ID="vLoginEmail" runat="server" Display="dynamic" ControlToValidate="txtLoginEmail" ForeColor="Red" ValidationGroup="validator" ErrorMessage="*Email obbligatoria"&gt;&lt;/asp:RequiredFieldValidator&gt;
                                          &lt;asp:RegularExpressionValidator ID="reLoginEmail" runat="server" ValidationGroup="validator" ControlToValidate="txtLoginEmail" Display="Dynamic" ForeColor="red" ErrorMessage="Inserire l'email nel formato corretto" SetFocusOnError="True" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"&gt;&lt;/asp:RegularExpressionValidator&gt;
                                      &lt;/div&gt;
                                      &lt;div class="form-group"&gt;
                                          &lt;div class="input-group"&gt;
                                              &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-lock"&gt;&lt;/i&gt;&lt;/div&gt;
                                              &lt;asp:TextBox type="password" ID="txtLoginPassword" class="form-control" placeholder="Password" runat="server"&gt;&lt;/asp:TextBox&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                      &lt;asp:Button ID="btnLogin" OnClick="btnLogin_Click" CssClass="btn btn-danger" data-loading-text="Signing In...." ValidationGroup="validator" runat="server" Text="Accedi"&gt;&lt;/asp:Button&gt;
                                      &lt;input id="resetLogin" class="btn btn-danger" runat="server" type="reset" value="reset" /&gt;
  
                                      &lt;div class="clearfix"&gt;&lt;/div&gt;
                                      &lt;div class="login-modal-footer"&gt;
                                          &lt;div class="row"&gt;
                                              &lt;div class="col-xs-8 col-sm-8 col-md-8"&gt;
                                                  &lt;i class="fa fa-lock"&gt;&lt;/i&gt;
                                                  &lt;a href="javascript:;" class="forgetpass-tab"&gt;Recupero &lt;/a&gt;
  
                                              &lt;/div&gt;
  
                                              &lt;div class="col-xs-4 col-sm-4 col-md-4"&gt;
                                                  &lt;i class="fa fa-check"&gt;&lt;/i&gt;
                                                  &lt;a href="javascript:;" class="signup-tab"&gt;Registrati &lt;/a&gt;
                                              &lt;/div&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
  
                                  &lt;/div&gt;
                                  &lt;%-- REGISTRAZIONE --%&gt;
                                  &lt;div role="tabpanel" class="tab-pane" id="profile"&gt;
  
                                      &lt;div class="clearfix"&gt;&lt;/div&gt;
                                      &lt;div class="form-group"&gt;
                                          &lt;div class="input-group"&gt;
  
                                              &lt;label class="radio-inline"&gt;
                                                  &lt;asp:RadioButton ID="rbUtente" GroupName="rbTipologia" Checked="true" runat="server" /&gt;Utente&lt;/label&gt;
  
                                              &lt;label class="radio-inline"&gt;
                                                  &lt;asp:RadioButton ID="rbRistoratore" GroupName="rbTipologia" runat="server" /&gt;Ristoratore&lt;/label&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                      &lt;div class="form-group"&gt;
                                          &lt;div class="input-group"&gt;
                                              &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-user"&gt;&lt;/i&gt;&lt;/div&gt;
  
                                              &lt;%-- username --%&gt;
                                              &lt;asp:TextBox class="form-control" ID="txtNome" placeholder="Nome" runat="server"&gt;&lt;/asp:TextBox&gt;
                                          &lt;/div&gt;
                                          &lt;asp:RequiredFieldValidator ID="vtxtNome" runat="server" Display="dynamic" ControlToValidate="txtNome" ForeColor="Red" ValidationGroup="validator2" ErrorMessage="*Nome obbligatorio"&gt;&lt;/asp:RequiredFieldValidator&gt;
  
                                      &lt;/div&gt;
                                      &lt;%-- cognome --%&gt;
                                      &lt;div class="form-group "&gt;
                                          &lt;div class="input-group "&gt;
                                              &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-user"&gt;&lt;/i&gt;&lt;/div&gt;
                                              &lt;asp:TextBox class="form-control" ID="txtCognome" placeholder="Cognome" runat="server"&gt;&lt;/asp:TextBox&gt;
                                          &lt;/div&gt;
                                          &lt;asp:RequiredFieldValidator ID="vCognome" runat="server" Display="dynamic" ControlToValidate="txtCognome" ForeColor="Red" ValidationGroup="validator2" ErrorMessage="*Cognome obbligatorio"&gt;&lt;/asp:RequiredFieldValidator&gt;
  
                                      &lt;/div&gt;
                                      &lt;%-- email --%&gt;
                                      &lt;div class="form-group"&gt;
                                          &lt;div class="input-group"&gt;
                                              &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-at"&gt;&lt;/i&gt;&lt;/div&gt;
                                              &lt;asp:TextBox class="form-control" ID="txtEmail" placeholder="Email" runat="server"&gt;&lt;/asp:TextBox&gt;
  
                                          &lt;/div&gt;
                                          &lt;asp:RequiredFieldValidator ID="vEmail" runat="server" Display="dynamic" ControlToValidate="txtEmail" ForeColor="Red" ValidationGroup="validator2" ErrorMessage="*Email obbligatoria"&gt;&lt;/asp:RequiredFieldValidator&gt;
                                          &lt;asp:RegularExpressionValidator ID="reEmail" runat="server" ValidationGroup="validator2" ControlToValidate="txtEmail" Display="Dynamic" ForeColor="red" ErrorMessage="Inserire l'email nel formato corretto" SetFocusOnError="True" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"&gt;&lt;/asp:RegularExpressionValidator&gt;
                                      &lt;/div&gt;
                                      &lt;%-- password --%&gt;
                                      &lt;div class="form-group "&gt;
                                          &lt;div class="input-group "&gt;
                                              &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-lock"&gt;&lt;/i&gt;&lt;/div&gt;
                                              &lt;asp:TextBox type="password" class="form-control" ID="txtPassword" placeholder="Password" runat="server"&gt;&lt;/asp:TextBox&gt;
  
                                          &lt;/div&gt;
                                          &lt;asp:RequiredFieldValidator ID="vPassword" runat="server" Display="dynamic" ControlToValidate="txtPassword" ForeColor="Red" ValidationGroup="validator2" ErrorMessage="*Password obbligatoria"&gt;&lt;/asp:RequiredFieldValidator&gt;
                                          &lt;asp:RegularExpressionValidator ID="rePassword" runat="server" ValidationGroup="validator2" ControlToValidate="txtPassword" Display="Dynamic" ForeColor="red" ErrorMessage="La password deve contenere: minimo 8 caratteri; almeno 1 maiuscola; almeno 1 minuscola; almeno 1 numero" SetFocusOnError="True" ValidationExpression="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,15}$"&gt;&lt;/asp:RegularExpressionValidator&gt;
  
                                      &lt;/div&gt;
  
                                      &lt;%-- password controllo --%&gt;
                                      &lt;div class="form-group "&gt;
                                          &lt;div class="input-group"&gt;
                                              &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-lock"&gt;&lt;/i&gt;&lt;/div&gt;
                                              &lt;asp:TextBox type="password" class="form-control" ID="txtCPassword"  placeholder="Conferma password" runat="server"&gt;&lt;/asp:TextBox&gt;
                                          &lt;/div&gt;
                                          &lt;asp:CompareValidator ID="cvPassword" ValidationGroup="validator2" Display="Dynamic" runat="server" ForeColor="Red" ControlToCompare="txtPassword" ControlToValidate="txtCPassword" ErrorMessage="La password non corrisponde"&gt;&lt;/asp:CompareValidator&gt;
                                              &lt;asp:Label ID="lblRegistrazione" Visible="false" runat="server" &gt;&lt;/asp:Label&gt;
                                      &lt;/div&gt;
  
  
  
  
                                      &lt;asp:Button ID="btnSignin" CssClass="btn btn-danger " data-loading-text="Registrando...." OnClick="btnSignin_Click" ValidationGroup="validator2" runat="server" Text="Registrati"&gt;&lt;/asp:Button&gt;
                                      &lt;input id="r2" class="btn btn-danger" runat="server" type="reset" value="reset" /&gt;
  
  
                                      &lt;div class="clearfix"&gt;&lt;/div&gt;
                                      &lt;div class="login-modal-footer"&gt;
                                          &lt;div class="row"&gt;
                                              &lt;div class="col-xs-8 col-sm-8 col-md-8"&gt;
                                                  &lt;i class="fa fa-lock"&gt;&lt;/i&gt;
                                                  &lt;a href="javascript:;" class="forgetpass-tab"&gt;Password dimenticata? &lt;/a&gt;
  
                                              &lt;/div&gt;
  
                                              &lt;div class="col-xs-4 col-sm-4 col-md-4"&gt;
                                                  &lt;i class="fa fa-check"&gt;&lt;/i&gt;
                                                  &lt;a href="javascript:;" class="signin-tab"&gt;Registrati&lt;/a&gt;
                                              &lt;/div&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
  
                                  &lt;/div&gt;
  
  
                                  &lt;div role="tabpanel"  class="tab-pane text-center"  id="forget_password"&gt;
                                      &amp;nbsp;&amp;nbsp;
                                  &lt;div class="clearfix"&gt;&lt;/div&gt;
                                      &lt;%--RECUPERO  --%&gt;
                                      &lt;div class="form-group"&gt;
                                          &lt;div class="input-group"&gt;
                                              &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-at"&gt;&lt;/i&gt;&lt;/div&gt;
                                              &lt;asp:TextBox class="form-control" ID="txtRecEmail" placeholder="Email" runat="server"&gt;&lt;/asp:TextBox&gt;
  
  
                                          &lt;/div&gt;
                                          &lt;asp:Label ID="lblRecovery" runat="server" &gt;&lt;/asp:Label&gt;
                                          &lt;asp:RequiredFieldValidator ID="vREmail" runat="server" Display="dynamic" ControlToValidate="txtRecEmail" ForeColor="Red" ValidationGroup="validator3" ErrorMessage="*Email obbligatoria"&gt;&lt;/asp:RequiredFieldValidator&gt;
                                          &lt;asp:RegularExpressionValidator ID="reREmail" runat="server" ValidationGroup="validator3" ControlToValidate="txtRecEmail" Display="Dynamic" ForeColor="red" ErrorMessage="Inserire l'email nel formato corretto" SetFocusOnError="True" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"&gt;&lt;/asp:RegularExpressionValidator&gt;
  
                                           &lt;/div&gt;
  
                                      &lt;asp:Button  ID="btnRecovery" OnClick="btnRecovery_Click" CssClass="btn btn-danger reco" data-loading-text="Invio...." ValidationGroup="validator3"  runat="server"&gt;&lt;/asp:Button&gt;
                                      &lt;div class="clearfix"&gt;&lt;/div&gt;
                                      &lt;div class="login-modal-footer"&gt;
                                          &lt;div class="row"&gt;
                                              &lt;div class="col-xs-6 col-sm-6 col-md-6"&gt;
                                                  &lt;i class="fa fa-lock"&gt;&lt;/i&gt;
                                                  &lt;a href="javascript:;" class="signin-tab"&gt;Registrazione &lt;/a&gt;
  
                                              &lt;/div&gt;
  
                                              &lt;div class="col-xs-6 col-sm-6 col-md-6"&gt;
                                                  &lt;i class="fa fa-check"&gt;&lt;/i&gt;
                                                  &lt;a href="javascript:;" class="signup-tab"&gt;Accesso &lt;/a&gt;
                                              &lt;/div&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
  
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>It has 3 tabs: Signin (LOGIN), Signup (Registrazione) and forgot password (RECUPERO).</p>
  
  <p>It is a bit 'difficult to explain but I'll try:
  In the 3 cards I have 3 buttons.
  If I am in my third card and I press enter key, the computer triggers the onclick event of the button that is located on the first tab.</p>
  
  <p>I tried this jquery code but it doesn't work:
  $(document).keypress(function (event) {</p>
  
  <pre><code>        var keycode = (event.keyCode ? event.keyCode : event.which);
          if (keycode == '13') {
              if ($('#home').is(":visible")) {
  
                  $("#btnLogin").trigger("click");
              }
              else if ($('#profile').is(":visible")) {
                  $("#btnSignin").trigger("click");
  
              }
              else {
                  $('#btnRecovery').click(ShowPopUp);
  
              }
  
          }
  
      }
           );
  </code></pre>
  
  <p>Do you have any solution?</p>
  
  <p>P.S.
  If I use the browser's console the javascript code work, but when i try it on my project it doesn't work...</p>
  
  <p>Please help me... this is my exam's project...</p>