I am trying to disable validation controls from JavaScript using the EnableValidator() method. The controls are within an ASP.NET Panel that can be enabled/disabled by selecting/clearing a checkbox. Following is the function that I have written to control the enabling/disabling of the validation controls.
function toogleValidationControlsForSource(targetControl, enableStatus){
var validators = targetControl.getElementsByTagName("span");
for (counter=0; counter < Page_Validators.length; counter++){
for (nestedCounter=0; nestedCounter < validators.length; nestedCounter++){
// Shortlist validators by excluding any span elements beloging to Label and other controls...
if (Page_Validators[counter].id == validators[nestedCounter].id){
ValidatorEnable(String(validators[nestedCounter].id), Boolean(enableStatus));
}
}
}
}When I call this function, I receive the following JavaScript error in Internet Explorer:
Line: 20
Char: 5
Error: 'style' is null or not an object
This wasted quite some of my time as I was unable to figure out where is it coming from within my code. Using the Firebug utility with Firefox, I have come to know that this error is coming from within
WebResource.axd. Following is the detail that Firefox provides:
val.style has no properties
ValidatorValidate(
"RequiredFieldValidator1", undefined, undefined)
WebResource.axd (line 215)
val.style.visibility = val.isvalid ? "hidden" : "visible"; (This is the line 20 in Web.axd that is causing the error)
My finding is that this error has something to do with ValidatorEnable(). If I remove or comment this line the error goes away. Can anyone help tell me why am I getting this error and how am I supposed
to get around with it?