title: Jquery validation engine not working with ASP.net update panel
body: <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;
      &lt;/asp:ScriptManager&gt;
      &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"&gt;
          &lt;ContentTemplate&gt;
              &lt;asp:MultiView ID="MultiView1" runat="server"&gt;
                  &lt;asp:View ID="View1" runat="server"&gt;
                      &lt;div class="box"&gt;
                          &lt;div class="head"&gt;
                              &lt;h1&gt;
                                  Currency&lt;/h1&gt;
                          &lt;/div&gt;
                          &lt;div class="inner"&gt;
                              &lt;table style="width: 100%"&gt;
                                  &lt;tr&gt;
                                      &lt;td style="width: 20%"&gt;
                                          &lt;asp:Button ID="btnv1AddNew" runat="server" CssClass="btn-success" Text="Add New"
                                              OnClick="btnv1AddNew_Click" TabIndex="1" /&gt;
                                      &lt;/td&gt;
                                      &lt;td style="width: 50%" align="right"&gt;
                                          Currency Name:
                                      &lt;/td&gt;
                                      &lt;td style="width: 20%"&gt;
                                          &lt;asp:TextBox ID="txtv1CurrencyName" runat="server" Width="80%" CssClass="control-textbox"
                                              TabIndex="2" AutoPostBack="True" OnTextChanged="txtv1CurrencyName_TextChanged"&gt;&lt;/asp:TextBox&gt;
                                      &lt;/td&gt;
                                      &lt;td style="width: 10%"&gt;
                                          &lt;asp:Button ID="btnv1Search" runat="server" CssClass="btn-success" Text="Search"
                                              OnClick="btnv1Search_Click" TabIndex="3" /&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td colspan="4"&gt;
                                          &lt;asp:GridView ID="gvCurrency" runat="server" CssClass="mGrid" HorizontalAlign="Center"
                                              Width="100%" AutoGenerateColumns="False" OnRowCommand="gvCurrency_RowCommand"
                                              AllowPaging="True" OnPageIndexChanging="gvCurrency_PageIndexChanging"&gt;
                                              &lt;Columns&gt;
                                                  &lt;asp:TemplateField HeaderText="Currency Code"&gt;
                                                      &lt;ItemTemplate&gt;
                                                          &lt;asp:Label ID="lblv2CurrencyCode" runat="server" Text='&lt;%# Bind("CurrencyCode") %&gt;'&gt;&lt;/asp:Label&gt;
                                                      &lt;/ItemTemplate&gt;
                                                  &lt;/asp:TemplateField&gt;
                                                  &lt;asp:TemplateField HeaderText="Currency Name"&gt;
                                                      &lt;ItemTemplate&gt;
                                                          &lt;asp:Label ID="lblv2CurrencyName" runat="server" Text='&lt;%# Bind("CurrencyName") %&gt;'&gt;&lt;/asp:Label&gt;
                                                      &lt;/ItemTemplate&gt;
                                                  &lt;/asp:TemplateField&gt;
                                                  &lt;asp:TemplateField ShowHeader="False"&gt;
                                                      &lt;ItemTemplate&gt;
                                                          &lt;asp:ImageButton ID="imgbtnView" runat="server" CommandArgument="&lt;%# Container.DisplayIndex %&gt;"
                                                              CommandName="ViewData" ImageUrl="~/Images/icon_view.png" ToolTip="View" /&gt;
                                                      &lt;/ItemTemplate&gt;
                                                      &lt;ItemStyle HorizontalAlign="Center" Width="3%" /&gt;
                                                  &lt;/asp:TemplateField&gt;
                                                  &lt;asp:TemplateField ShowHeader="False"&gt;
                                                      &lt;ItemTemplate&gt;
                                                          &lt;asp:ImageButton ID="imgbtnEdit" runat="server" CommandArgument="&lt;%# Container.DisplayIndex %&gt;"
                                                              CommandName="EditData" ImageUrl="~/Images/icon_edit.png" ToolTip="Edit" /&gt;
                                                      &lt;/ItemTemplate&gt;
                                                      &lt;ItemStyle HorizontalAlign="Center" Width="3%" /&gt;
                                                  &lt;/asp:TemplateField&gt;
                                                  &lt;asp:TemplateField ShowHeader="False"&gt;
                                                      &lt;ItemTemplate&gt;
                                                          &lt;asp:ImageButton ID="imgbtnDelete" runat="server" CommandArgument="&lt;%# Container.DisplayIndex %&gt;"
                                                              OnClientClick="return ConfirmOnDelete();" CommandName="DeleteData" ImageUrl="~/Images/icon_delete.png"
                                                              ToolTip="Delete" /&gt;
                                                      &lt;/ItemTemplate&gt;
                                                      &lt;ItemStyle HorizontalAlign="Center" Width="3%" /&gt;
                                                  &lt;/asp:TemplateField&gt;
                                              &lt;/Columns&gt;
                                              &lt;PagerStyle CssClass="pgr" /&gt;
                                              &lt;AlternatingRowStyle CssClass="alt" /&gt;
                                          &lt;/asp:GridView&gt;
                                          &lt;div class="text-right badge"&gt;
                                              &lt;asp:Label ID="lblCount" runat="server"&gt;&lt;/asp:Label&gt;
                                          &lt;/div&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/table&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/asp:View&gt;
                  &lt;asp:View ID="View2" runat="server"&gt;
                      &lt;div class="box"&gt;
                          &lt;div class="head"&gt;
                              &lt;h1&gt;
                                  Currency&lt;/h1&gt;
                          &lt;/div&gt;
                          &lt;div class="inner"&gt;
                              &lt;table style="width: 100%"&gt;
                                  &lt;tr&gt;
                                      &lt;td class="tdleftcolumn"&gt;
                                          &lt;span class="textfield"&gt;Currency Code:&lt;/span&gt;
                                      &lt;/td&gt;
                                      &lt;td class="tdrightcolumn"&gt;
                                          &lt;asp:TextBox ID="txtv2CurrencyCode" runat="server" CssClass="control-textbox validate[required,custom[onlyLetterSp]]"
                                              MaxLength="3" TabIndex="1" Width="20%" AutoPostBack="True" OnTextChanged="txtv2CurrencyCode_TextChanged"&gt;&lt;/asp:TextBox&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td class="tdleftcolumn"&gt;
                                          &lt;span class="textfield"&gt;Currency Name:&lt;/span&gt;
                                      &lt;/td&gt;
                                      &lt;td class="tdrightcolumn"&gt;
                                          &lt;asp:TextBox ID="txtv2CurrencyName" runat="server" Width="50%" CssClass="control-textbox validate[required,custom[onlyLetterSp]]"
                                              MaxLength="50" TabIndex="2"&gt;&lt;/asp:TextBox&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td class="tdleftcolumn"&gt;
                                          &amp;nbsp;
                                      &lt;/td&gt;
                                      &lt;td class="tdrightcolumn"&gt;
                                          &amp;nbsp;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td class="tdleftcolumn"&gt;
                                          &amp;nbsp;
                                      &lt;/td&gt;
                                      &lt;td class="tdrightcolumn"&gt;
                                          &lt;asp:Button ID="btnv2Add" runat="server" CssClass="btn-success" OnClick="btnv2Add_Click"
                                              TabIndex="3" Text="Add" /&gt;
                                          &lt;asp:Button ID="btnv2Confirm" runat="server" Text="Confirm" CssClass="btn-success"
                                              OnClick="btnv2Confirm_Click" TabIndex="4" /&gt;
                                          &lt;asp:Button ID="btnv2Save" runat="server" CssClass="btn-success" OnClick="btnv2Save_Click"
                                              TabIndex="5" Text="Save" /&gt;
                                          &lt;asp:Button ID="btnv2Edit" runat="server" CssClass="btn-primary" OnClick="btnv2Edit_Click"
                                              TabIndex="6" Text="Edit" /&gt;
                                          &lt;asp:Button ID="btnv2Delete" runat="server" CssClass="btn-danger" OnClick="btnv2Delete_Click"
                                              OnClientClick="return confirm('Are you sure you want to delete?');" TabIndex="7"
                                              Text="Delete" /&gt;
                                          &lt;asp:Button ID="btnv2Clear" runat="server" CssClass="btn-warning" OnClick="btnv2Clear_Click"
                                              TabIndex="8" Text="Clear" /&gt;
                                          &lt;asp:Button ID="btnv2Cancel" runat="server" CssClass="btn-warning" OnClick="btnv2Cancel_Click"
                                              TabIndex="9" Text="Cancel" /&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                                      &lt;td class="tdleftcolumn"&gt;
                                          &amp;nbsp;
                                      &lt;/td&gt;
                                      &lt;td class="tdrightcolumn"&gt;
                                          &lt;asp:Label ID="lblErrorAdd" runat="server" CssClass="control-label"&gt;&lt;/asp:Label&gt;
                                      &lt;/td&gt;
                                  &lt;/tr&gt;
                              &lt;/table&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/asp:View&gt;
              &lt;/asp:MultiView&gt;
          &lt;/ContentTemplate&gt;
      &lt;/asp:UpdatePanel&gt;
      &lt;script type="text/javascript"&gt;
          Sys.Application.add_load(jScript);
  
          function jScript() {
              $("[id*=btnv2Add]").click(function () {
                  $("#ctl01").validationEngine('attach', { promptPosition: "topRight" });
              });
              $("[id*=btnv2Save]").click(function () {
                  $("#ctl01").validationEngine('attach', { promptPosition: "topRight" });
              });
              $("[id*=btnv2Clear]").click(function () {
                  $("#ctl01").validationEngine('detach');
              });
              $("[id*=btnv2Cancel]").click(function () {
                  $("#ctl01").validationEngine('detach');
              });
          };
  
          var prm = Sys.WebForms.PageRequestManager.getInstance();
          if (prm != null) {
              prm.add_initializeRequest(function (sender, e) {
                  if (sender._postBackSettings.panelsToUpdate.join().indexOf("UpdatePanel1") != -1) {
                      if (!$("[id*=UpdatePanel1]").validationEngine('validate')) {
                          e.set_cancel(true);
                      }
                  }
              });
          }
      &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>My form validation is not working when I put update panel to the form. Validation engine only attach when hit the <code>btnv2Add</code>. How can I resolve this problem? I herewith attached my asp.net source and the java script.</p>