Sunday, October 05, 2008

XHTML 1.1 strictly ASP.Net

For those of you who are interested in web standards, you may have noticed that when you create an ASP.Net application the standard project item templates create a web page that complies to the XHTML 1.0 Transitional doctype. This may or may not be what you want.  XHTML 1.0 Transitional is for existing websites that are in the process of migrating, or if a website specifically needs to support browsers that don't know about CSS. This is because XHTML Transitional still supports the presentation based tags such as <font> and <center>. New websites however, should generally adhere to the XHTML 1.1 strict doctype which does a better job of enforcing separation of content from presentation. So as an ASP.Net developer I have to re-jig all my pages when I add them into my solution, to comply with this doctype.

 

No longer do I have to do all this manual work, thanks to a fellow Readify colleague, Damian Edwards, who's work I really admire and respect, you can now add proper XHTML 1.1 strict templates when developing ASP.Net applications. Damian has created this CodePlex project that installs XHTML compliant item templates for ASP.Net Web Project items such as Web Form, Master Page, Ajax Web Form, Ajax Master Page, HTML Page, and StyleSheet for Visual Studio 2008.

 

Note : you also have to add the following to your web.config

<xhtmlConformance mode="Strict"/>

This tells the ASP.Net rendering engine... "no I really meant it when I said strict, and I know what I'm talking about."

What does this guarantee you as an ASP.Net developer?

Because of ASP.Net's browser capabilities detection mechanism, what this guarantees you is that when ASP.Net is serving a page to a modern browser, it will serve XHTML 1.1 strict compliant markup. Be careful, this does not necessarily mean that your site will validate with the W3C Validation Service, in fact I've been caught out on this one before.

This reminds me that I've been meaning for a long time now, to write a more concise article on developing standards compliant web pages in ASP.Net, I'll put it on my daily goals list, item #44 right after "learn Spanish". (sorry for those who don't quite get the obscure red dwarf reference).

No comments:

Post a Comment