Validation ASP.Net Tutorial

Value:   the value of the  form field being validated.
IsValid: whether validation fails or succeeds.
ValidateEmptyText: whether validation is performed without a value.
<%@ Page Language="C#" %>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    void valComments_ServerValidate(Object source, ServerValidateEventArgs args)
    {
        if (args.Value.Length > 10)
            args.IsValid = false;
        else
            args.IsValid = true;
    }



    
    function valComments_ClientValidate(source, args)
    {
        if (args.Value.length > 10)
            args.IsValid = false;
        else
            args.IsValid = true;
    }
    
    Show CustomValidator with JavaScript


    
    

            id="lblComments"
        Text="Comments:"
        AssociatedControlID="txtComments"
        Runat="server" />
    
            id="txtComments"
        TextMode="MultiLine"
        Columns="30"
        Rows="5"
        Runat="server" />
            id="valComments"
        ControlToValidate="txtComments"
        Text="(Comments must be less than 10 characters)"
        OnServerValidate="valComments_ServerValidate"
        ClientValidationFunction="valComments_ClientValidate"
        Runat="server" />
            id="btnSubmit"
        Text="Submit"
        Runat="server" />