Search code examples
c#javascriptasp.netrequiredfieldvalidator

How to hide a validator's error text when the validator is initially enabled


I've got the following javascript code, which enables a bunch of validators.

ValidatorEnable(document.getElementById("<%=AddressValidator.ClientID %>"), true);
ValidatorEnable(document.getElementById("<%=CityValidator.ClientID %>"), true);
ValidatorEnable(document.getElementById("<%=CountryValidator.ClientID %>"), true);

My problem is that when the validators are enabled with the above code, the error message (i.e. the validation text) is displayed. How can I hide the error message just for this instance when they're being enabled?


Solution

  • If you want to enable it without validating:

    document.getElementById("<%=AddressValidator.ClientID %>").enabled = true;
    

    Because ValidatorEnable internally looks like:

    function ValidatorEnable(val, enable) { 
        val.enabled = (enable != false); 
        ValidatorValidate(val); 
        ValidatorUpdateIsValid(); 
    }
    

    http://sandblogaspnet.blogspot.de/2009/04/calling-validator-controls-from.html