Dot NET
Dot NET

Reputation: 4897

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?

Upvotes: 4

Views: 4380

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460118

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

Upvotes: 21

Related Questions