Wednesday, May 03, 2006

ASP.NET validators and other browsers

I developed a little app last night that used the builtin ASP.NET validators. Now that I am running firefox as my default browser I have discovered that the validators client script does not work in anything other than IE. The reason for this is that the BaseValidator class (all validation controls derive from this class) have methods the emit javascript to do the validation. This script also contains an array of validator controls and summaries that looks like this:

var Page_ValidationSummaries = new Array(document.all["ValidationSummary1"]);
var Page_Validators = new Array(document.all["RequiredFieldValidator1"], document.all["RequiredFieldValidator2"], document.all["RequiredFieldValidator3"], document.all["RequiredFieldValidator4"], document.all["RegularExpressionValidator1"], document.all["RequiredFieldValidator5"]);

And therin lies the problem. Only IE uses document.all every other browser I know off does not recognize document.all. Instead what should have been used is document.getElementById to get the controls.

There are two ways I see to fix this. The first is to just download a replacement validator suite like this free one. I have not tried it (so I appreciate some feedback if you do). Instead I am going to do things the hard way and fix the javascript issues by creating a class that emits compatable javascript for all browsers. I do it the hard way so that I can better understand what is going on internally and seems to help me build better solutions.

Update. It is now 9pm and I am frustrated. I have made a ton of progress towards this goal but am having issues with the runtime not wanting to run my override (I assume this is because it thinks firefox can only do html 3.2 not 4.0 like the all mighty IE). I am going to leave this for a while and get some beer therapy and maybe try more tommorow. I will post the code once I get a solution figured out.


Post a Comment

<< Home