ASP CustomValidator, advancing to postback after error

后端 未结 3 711
死守一世寂寞
死守一世寂寞 2021-01-22 19:55

I have an ASP .NET page with ASP validators (Required Field, Regular Expression,...) plus java script functions for additional validation (for example, to check if second date b

3条回答
  •  难免孤独
    2021-01-22 20:24

    like @Jason wrote, when using CustomValidator client is excepting for source and arguments params. a quick sample of use both client and server side with CustomValidator.

    CustomValidator use ClientValidationFunction and OnServerValidate properties:

    *
    

    Client side validation:

    var Validators = {
    CardNumber: function (source, clientside_arguments) {
    
        var valid_val = true;
        var txtCardNumber = clientside_arguments.Value; //(return the ControlToValidate value)
    
        //make your checks here
    
        clientside_arguments.IsValid = valid_val;
    }}
    

    server side validation:

    protected void ValidateCreditCardValid(object sender, ServerValidateEventArgs e)
        {
           //make your checks here            
           e.IsValid = false;
    
        }
    

提交回复
热议问题