Enable/Disable RequiredFieldValidator with Javascript

Sometimes you may need to enable/disable validators on client side. you can easily do this using ValidatorEnable function in the Asp.net javacsript Script Library. Here is an example:

 <script language="javascript" type="text/javascript">
function EnableDisableVote() {
var radio = document.getElementById('<%= rdoYesNo.ClientID %>');
var radioArray = radio.getElementsByTagName("input");
var isChecked = false;
for (var i = 0; i < radioArray.length; i++) {
var item = radioArray[i];
if (item.type == "radio" && item.checked) {
isChecked = true;
if (i > 0) {
document.getElementById('<%= TextBoxCaseNotes.ClientID %>').disabled = false;
ValidatorEnable(document.getElementById('<%= RequiredFieldValidatorCasseNotes.ClientID %>'), true);
}
else {
document.getElementById('<%= TextBoxCaseNotes.ClientID %>').value = '';
document.getElementById('<%= TextBoxCaseNotes.ClientID %>').disabled = true;
ValidatorEnable(document.getElementById('<%= RequiredFieldValidatorCasseNotes.ClientID %>'), false);
}
break;
}
}
if (isChecked && document.getElementById('<%= ChkIagree.ClientID %>').checked) {
document.getElementById('<%= ButtonVote.ClientID %>').disabled = false;
}
else
document.getElementById('<%= ButtonVote.ClientID %>').disabled = true;
}
</script>

Ebook Download
View all
Learn
View all
F11Research & Development, LLC