how to stop a series of validators in a validationgroup to stop firing upon error? asp.net

270 Views Asked by At

there are 3 validators on an textbox,

asp:RegularExpressionValidator asp:RangeValidator asp:CompareValidator

some input will trigger all 3 of them, how can I stop firing the rest upon any error?

1

There are 1 best solutions below

0
On

May be this can help you.. you can intercept ValidatorValidate method of ASP.Net validation framework and selectively disabled the validator controls you want based on any given validation control result.

<asp:TextBox ID="tbText" runat="server"></asp:TextBox>

<asp:RegularExpressionValidator EnableClientScript="true" ValidationExpression="\d" ID="rang" runat="server" ControlToValidate="tbText" >sdfsdfsdfsdfsdfsd</asp:RegularExpressionValidator>
<asp:RangeValidator EnableClientScript="true" Type="Date" MinimumValue="10/10/2000" MaximumValue="10/10/2013" runat="server" ID="rang2" ControlToValidate="tbText" >23444444444444</asp:RangeValidator>
<asp:Button ID="btn" runat="server" Text="submit"/>



<script language="javascript">
    var oldValidatorValidate = ValidatorValidate;
    function MyValidatorValidate(val, validationGroup, event) {



        //first call the original one
        oldValidatorValidate(val, validationGroup, event);

        //Here you can check val.isvalid - e.g write your logic here, like check for the correct validator etc etc
        //alert(val.id + ":" + val.isvalid);
        if (!val.isvalid) {
            var myVal = document.getElementById('<%=rang2.ClientID %>');
            //ValidatorEnable(myVal, false);
        }





    }
    ValidatorValidate = MyValidatorValidate;
</script>