Duplicated RRS feed


  • User214976711 posted


    I am employing client-side validation. From the example above, we found that they use both validation on client-side and server side functions. Can we remove OnServerValidate from CustomValidator?

    Yes can remove OnServerValidate, here is the simple example, which demostrates, if the user enters more than 6 characters


    is fired and returns "args.IsValid = false":

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <script type="text/javascript" src="jquery-1.7.1.js"></script>
        <script type="text/javascript">
            function ValidateUserName(source, args) {
                var textBox = $('#<%= TextUserName.ClientID%>').val();
                if (textBox.length > 6) {
                    args.IsValid = false;
                    return false;
                args.IsValid = true;
                return true;
        <form id="form1" runat="server">
            <asp:TextBox ID="TextUserName" runat="server"></asp:TextBox>
            <asp:CustomValidator ID="CustomValidatorUser" runat="server" ControlToValidate="TextUserName"
                        ErrorMessage="Minimum of 6 (six) alphanumeric characters." ClientValidationFunction="ValidateUserName"
                        Display="Dynamic" ValidateEmptyText="True"></asp:CustomValidator>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 23, 2012 10:08 PM