Search code examples
asp.netvb.netcustomvalidator

Validator: How to disable ServerSide validation if ClientSide fails


I'm making a page where user enters a card number and I have a number of validators attached to the textbox.

First one is RequiredFieldValidator

Second is RegularExpressionValidator

Third one is a CustomValidator with OnServerValidate="validateServer" and ClientValidationFunction="validateClient"

TThe custom one executes client side validator and then server side. I want the server side to NOT be hit if the regex validator fails. In the custom client side code I check for regex validator and return True (so that I do not have double error message, one from REGEX and one from CUSTOM validators), but how do i disable server validation on custom validator? I cant figure that out.

I tried this on client side validator, but the server side validator still gets hit:

if (!document.getElementById("myRegexValidator").isvalid) {
    args.IsValid = true; 
    return false;
}

Solution

  • Never mind.

    The server side validator does not execute if client side validator fails.

    The reason why server side was executing on my side is because the client side had javascript error that I did not catch (pause on JS errors was disabled). Because of JS error in the IF statement, the server side validation always kicked in.