Share via


Validation Controls and non Microsoft Browsers

 

There are a few times during the course of cross platform functional testing of your ASP.NET Application one would run into this. Here's one of my recent experiences.

Platform: ASP.NET 1.1 on Windows Operating Systems.

IDE: Visual Studio .NET 2002/Visual Studio .NET 2003

PROBLEM: When you use validation controls in your ASP.NET webforms, you notice that it automatically adds a client side script in the HTML that is sent down to the browser. This allows for client side validation avoiding a post back. While this works very well in Internet Explorer 5.5 and above, it may not be the case with Internet Explorer version lesser than 5.5 and other non Microsoft browsers and other down level browsers. ASP.NET determines the client browser type that is making the request and sends an appropriate HTML. By default ASP.NET sends HTML 4.0 compliant markup to Internet Explorer version 5.5 and above and HTML 3.2 compliant markup to non Microsoft browsers. Note that many of the new browsers out there can still handle HTML 4.0 based markup. You can configure ASP.NET to send HTML 4.0 markups to these browsers. However client side validation controls may not work as you expect.

If you include a client side script and hit the submit button, you will still notice a postback to the server. The reason this will happen is because of the type of client side script emitted by the BaseValidator of ASP.NET. This includes JavaScript code which in turn creates an aray of validators. This array is registed in the BaseValidator's RegisterValidatorDeclaration method so that validators are then invoked on the client side before the form is posted back. However, the client side script uses "document.all" script instead if "getElementByID". document.all is supported only by Internet Explorer. If this script is sent to a non Microsoft browser it will inturn generate JavaScript Errors.

I recently got a support case from one of my customer's with this exact issue asking if we provided a hotfix. I explained that this is not something that is broken, but a design feature of ASP.NET and therefore no hotfix. Various browsers follow various standards and I believe this might be a reason why this works the way it is in ASP.NET 1.x. Though you can edit the WebUIValidation.JS script file that is installed by the .NET Framework, it is not recommended at all. Another solution will be to include your own client side validation script that will be called in that page. But this makes it maintaining the code difficult. Here's a nice article on MSDN

Multi browser support in ASP.NET
https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNet-JSPMig-MultiBrowserSupport.asp
 
Now for some good news: Try ASP.NET 2.0. With this version, there has been a significant change to the way the script is handled and PLUS, the most important thing is you will not see a postback happening during validation in non-Microsoft browsers like FireFox. Take a look at:
 
Changes to the Validation Controls in ASP.NET 2.0
https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/ValGroups.asp

Please feel free to drop me an email if you have any question about this post.