Custom Validator not validating for textbox


March 2019


7 time


I'm a Beginner.

I'm creating a Registration Form. I want the user to input a Username with at least 5 characters. But, my Custom Validator > isn't validating my textbox. Yes, It must be a Custom Validator.

Any help is greatly appreciated but, please provide a explanation so that I'm able to understand and use that knowledge for further projects.

Here is my code:

<tr><td class="auto-style3" >
        <asp:Label ID="Label1" runat="server" Text="Username: "></asp:Label>
        <asp:TextBox ID="Username" runat="server" CssClass="auto-style7" Width="113px"></asp:TextBox>
        <asp:CustomValidator ID="UsernameValidator" runat="server" ErrorMessage="*Must be at least 5 characters" ForeColor="#CC0000" OnServerValidate="UsernameValidator_ServerValidate" ControlToValidate="Username"></asp:CustomValidator>



        protected void UsernameValidator_ServerValidate(object sender, ServerValidateEventArgs e)
        e.IsValid = (Username.Text.Length > 5);

0 answers