As you may know, all components from the r.a.d.controls suite render XHTML 1.1 compliant output. We wanted to promote it in a way that all users can click a button in our online examples and see for themselves that everything validates perfectly. W3C provides an online validation service (http://validator.w3.org) so it should not be that hard. Unfortunately ASP.NET 1.x complies with *NO* HTML standard ever approved by W3C. ASP.NET 2.0 was first XHTML 1.1 compliant, but then in the official release Microsoft fell back to XHTML 1.0 transitional which is less restrictive.
I made a couple of Google searches and found other people who had the same problem. There were different approaches and we picked the one with custom page and regular expression replaces. As a result all live examples inherit from a page derived from System.Web.UI.Page. In the Render method the output is cleaned by a set of regular expressions to comply with the XHTML 1.1 specification. Here are all the problems solved by XhtmlPage:
- ViewState rendering
According to the XHTML 1.1 spec input elements should be enclosed in a tag with block display. In ASP.NET 1.x the ViewState is rendered as hidden inputs directly after the form tag. A regular expression captured all those hidden fields and enclosed them in a <div>.
- Name attribute of the form tag
- Script tags
At the end of this endeavor I really became a regular expression ninja and nothing seemed impossible. However I should give credit to www.regexlib.com and their tester page: http://www.regexlib.com/RETester.aspx - it was really helpful and saved me lots of time to find the right regular expression hack.
However XhtmlPage does not magically cure all bad ASP.NET practices. Developers have to make sure the rest of the html is compliant – lowercase tag names, no unclosed tags. Here I will mention the rather annoying feature of Visual Studio 2002/2003 to capitalize some of the tags when switching between design and source view. It slowed us down a bit. Another thing to mention is that client-side validation controls cannot be made valid using that technique. They deeply rely on custom attributes which fail to validate. However server side validation can be used instead.
If you want to make XHTML compliant pages but cannot switch immediately to ASP.NET 2.0, XhtmlPage is an option. The class is available from the Telerik.QuickStart.dll assembly which can be found in the bin folder of any r.a.d.control. We plan to release the source code soon.