ASP.NET: Custom Validation not working even when required field validator is used 
<p>Here is a code for my web form control</p>

<pre><code>&lt;asp:TextBox runat="server" ID="txtUsername"&gt;&lt;/asp:TextBox&gt;
&lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtUsername" runat="server" ErrorMessage="RequiredFieldValidator"&gt;&lt;/asp:RequiredFieldValidator&gt;
&lt;asp:CustomValidator OnServerValidate="checkUsername" ID="CustomValidator1" runat="server" ControlToValidate="txtUsername" EnableClientScript="true" ClientValidationFunction="checkUsername" ErrorMessage="CustomValidator"&gt;&lt;/asp:CustomValidator&gt;
</code></pre>

<p>Client side validation</p>

<pre><code>&lt;script type="text/javascript"&gt;
        function checkUsername(source,args){
        alert("test");
           /* alert(args.Value);
            args.IsValid=false;
            */
        }
    &lt;/script&gt;
</code></pre>

<p>Server side validation</p>

<pre><code>protected void checkUsername(object sender, System.Web.UI.WebControls.ServerValidateEventArgs e) {
            String str=e.Value;
            if(str.Length&gt;6)
            e.IsValid = false;
        }
</code></pre>

<p>But for some reason this Costom Validation is not firing . Any clues ?</p>

<p><em>EDIT:</em>
I am coding in asp for first time , Server validation is in code-behind class</p>

<p>Here is a code asp.net page , Maybe some small mistake I am making ?</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="lab1.Registration" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
&lt;head runat="server"&gt;
    &lt;title&gt;Untitled Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;

        &lt;asp:Button ID="Button1" runat="server" Text="Recreate table" 
            onclick="Button1_Click" /&gt;
        &lt;asp:GridView ID="GridView1" runat="server"&gt;
        &lt;/asp:GridView&gt;

    &lt;/div&gt;
    &lt;script type="text/javascript"&gt;
        function checkUsername(source,args){
        args.IsValid=(args.Value.length&lt;=6);
           /* alert(source.Value);
            args.IsValid=false;
            alert(document.getElementById("txtUsername").nodeValue);*/
        }
    &lt;/script&gt;
    &lt;asp:Table ID="Table1" runat="server" Height="106px" Width="469px"&gt;

        &lt;asp:TableRow&gt;
            &lt;asp:TableCell&gt;
                &lt;asp:Label runat="server" Text="Username"&gt;&lt;/asp:Label&gt;
            &lt;/asp:TableCell&gt;
            &lt;asp:TableCell&gt;
                &lt;asp:TextBox runat="server" ID="txtUsername"&gt;&lt;/asp:TextBox&gt;
                &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtUsername" runat="server" ErrorMessage="RequiredFieldValidator"&gt;&lt;/asp:RequiredFieldValidator&gt;
                &lt;asp:CustomValidator OnServerValidate="checkUsername" ID="CustomValidator1" runat="server" ControlToValidate="txtUsername" EnableClientScript="true" ClientValidationFunction="checkUsername" ErrorMessage="CustomValidator"&gt;&lt;/asp:CustomValidator&gt;

            &lt;/asp:TableCell&gt;
        &lt;/asp:TableRow&gt;

    &lt;/asp:Table&gt;

    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
