title: ASP.NET Custom validator for unique entry is not working
body: <p>I am trying to implement a custom validator  to comapare the values in database so that the entry is unique - in my registration page. </p>
  
  <p>This is my aspx page</p>
  
  <p></p>
  
  <pre><code>    &lt;h4&gt;  Sign up  &lt;/h4&gt;
  
      &lt;div class=""&gt;
          &lt;div class="status"&gt;
              &lt;asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableViewState="false"
                  ValidationGroup="EmployerRegister" HeaderText="Sorry we could not process request because:"
                  CssClass="error" /&gt;
          &lt;/div&gt;
  
          &lt;p class="input-block last"&gt;
              &lt;label for="&lt;%=uxEmployerName.ClientId %&gt;"&gt;
                  &lt;strong&gt;Company Name&lt;/strong&gt; (required)
              &lt;/label&gt;
  
              &lt;asp:TextBox ID="uxEmployerName" runat="server" CssClass="uxemail" TabIndex="10"
                  ValidationGroup="EmployerRegister" /&gt;
              &lt;asp:RequiredFieldValidator ID="uxEmployerNameValReq" runat="server" ControlToValidate="uxEmployerName"
                  ErrorMessage="You must enter Company Name." EnableClientScript="true"  Display="Dynamic"
                  ValidationGroup="EmployerRegister" /&gt;
          &lt;/p&gt;
  
  
          &lt;p class="input-block last"&gt;
              &lt;label for="&lt;%=uxEmail.ClientId %&gt;"&gt; &lt;strong&gt;Your Email&lt;/strong&gt; (required) &lt;/label&gt;
  
              &lt;asp:TextBox ID="uxEmail" runat="server" CssClass="uxemail" TabIndex="16" ValidationGroup="EmployerRegister" /&gt;
  
              &lt;asp:RequiredFieldValidator ID="uxEmailValReq" runat="server" ControlToValidate="uxEmail"
                  ErrorMessage="You must enter Email." EnableClientScript="true" Display="none"
                  ValidationGroup="EmployerRegister" /&gt;
  
              &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="The 'Email Address' you have entered does not appear to be a valid address."
                  ControlToValidate="uxEmail" EnableViewState="False" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                  ValidationGroup="EmployerRegister" Display="None" /&gt;
  
              &lt;asp:CustomValidator ID="uxEmailValUnique" runat="server" OnServerValidate="uxEmailValUnique_ServerValidate"  ErrorMessage="It appears that you already have an account with us."
                  ControlToValidate="uxEmail" EnableViewState="False" ValidationGroup="EmployerRegister"
                  Display="None" /&gt;
  
          &lt;/p&gt;
  
  
          &lt;p class="input-block last"&gt;
              &lt;asp:LinkButton runat="server" ID="uxRegisterButton" Text="Submit" CausesValidation="true"
                  ValidationGroup="EmployerRegister" CssClass="button" TabIndex="18" /&gt;
  
          &lt;/p&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>The server side code in vb.net page is </p>
  
  <pre><code>Private Sub uxEmailValUnique_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles uxEmailValUnique.ServerValidate
      args.IsValid = Not LocalHelper.EmailExists(uxEmail.Text)
  End Sub
  </code></pre>
  
  <p>the function in LocalHelper file is</p>
  
  <pre><code>Shared Function EmailExists(email As String) As Boolean
      Return DB.GetInteger("select count(id) from [user] where deleted = 0 and active = 1 and email = @email", DB.SIP("email", email)) &gt; 0
  End Function
  </code></pre>
  
  <p>but the custom validator is not working. its taking duplicate email address and not giving any error message. My database is connected properly. </p>
  
  <p>what is wrong in this code/ how to fix this.</p>