title: jquery validation equalto not working in ASP.net content page
body: <p>I have two textboxes for password and confirm password. But the validation using Jquery validation plugin is not working. My controls are in Content page.</p>
  
  <pre><code> &lt;asp:textbox TextMode="Password" runat="server" ID="txtPassword" required="True"  class="form-control"&gt;&lt;/asp:textbox&gt;
  
  
   &lt;asp:textbox TextMode="Password" runat="server" ID="txtConfPassword" required="True" equalto= "ContentPlaceHolder1_txtPassword"  class="form-control"&gt;&lt;/asp:textbox&gt;
  </code></pre>
  
  <p>I have even tried</p>
  
  <pre><code>equalto='&lt;%=txtPassword.UniqueID %&gt;' and equalto='&lt;%=txtPassword.ClientID %&gt;'
  </code></pre>
  
  <p>but its not working. My script is in master page as follows</p>
  
  <pre><code>function setFormValidation(id) {
            $(id).validate({
                highlight: function (element) {
                    $(element).closest('.form-group').removeClass('has-success').addClass('has-danger');
                    $(element).closest('.form-check').removeClass('has-success').addClass('has-danger');
                },
                success: function (element) {
                    $(element).closest('.form-group').removeClass('has-danger').addClass('has-success');
                    $(element).closest('.form-check').removeClass('has-danger').addClass('has-success');
                },
                errorPlacement: function (error, element) {
                    $(element).closest('.form-group').append(error);
                },
            });
        } 
  
      $(document).ready(function() {
            setFormValidation('#form1');
  });
  </code></pre>
  
  <p>All other validations are working fine. I understand the error happens when the id of the textbox changes in content page.</p>
  
  <p>please help. </p>
  
  <p><strong>edit 1</strong></p>
  
  <p>I have tried by adding the following script in master page. </p>
  
  <pre><code>$(id).validate({
                    rules: {
                        '&lt;%= this.ContentPlaceHolder1.FindControl("txtPassword").UniqueID %&gt;': {
                            required: true,
                            rangelength: [6, 15]
                        },
                        '&lt;%= this.ContentPlaceHolder1.FindControl("txtConfPassword").UniqueID %&gt;': {
                            required: true,
                            equalTo: '#&lt;%= this.ContentPlaceHolder1.FindControl("txtPassword").ClientID %&gt;'
                        }
                    },
                    messages: {
  
                        '&lt;%= this.ContentPlaceHolder1.FindControl("txtPassword").UniqueID %&gt;': {
                            required: "This field is required.",
                            rangelength: "Minimum 6 characters required"
                        },
  
                        '&lt;%= this.ContentPlaceHolder1.FindControl("txtConfPassword").UniqueID %&gt;': {
  
                            equalTo: "Please enter the same password again"
                        }
                    },
                    highlight: function (element) {
                        $(element).closest('.form-group').removeClass('has-success').addClass('has-danger');
                        $(element).closest('.form-check').removeClass('has-success').addClass('has-danger');
                    },
                    success: function (element) {
                        $(element).closest('.form-group').removeClass('has-danger').addClass('has-success');
                        $(element).closest('.form-check').removeClass('has-danger').addClass('has-success');
                    },
                    errorPlacement: function (error, element) {
                        $(element).closest('.form-group').append(error);
                    },
                })
  </code></pre>
  
  <p>It works fine for a specific page (say user.aspx). but when i navigate to any other page it will throw error 
  Object reference not set to an instance of an object.
  on  <code>'&lt;%= this.ContentPlaceHolder1.FindControl("txtPassword").UniqueID %&gt;':</code> 
  because that control wont be there in the content page</p>
  
  <p>i have tried to put if else condition in master page as </p>
  
  <pre><code>if (window.location.pathname == "/admin/AddUser.aspx") {
  </code></pre>
  
  <p>still it throws error</p>