Tuesday, November 26, 2013

Clearing a validation message from a Validator control of ASP.Net

In many situations we may land in a position to clear the validation messages raised by a Validator control, in a Javascript. Say for example a Required field validator raising a message "Please select any option".

If we need to clear the validation message from JavaScript, most of them will try the below code

document.getElementById('RequiredFieldValidatorClientID').innerHTML='';

If we use this line to clear the warning message, then this 'RequiredFieldValidator' will never display the validation message again. So, we have to set the CSS property "display" to "none".

document.getElementById('RequiredFieldValidatorClientID').style.display = "none";

In JQuery

$('#RequiredFieldValidatorClientID').css('display', 'none');

No comments:

Post a Comment