Mixing XHTML Document Types in ASP.Net 2.0

Submitted on Nov 22, 2006, 6:32 p.m.

As site I’ve been working on recently required that all pages be XHTML Transitional compliant, with one exception. A special document page of the site needed to be in XHTML Strict format.  The problem was how to get ASP.Net 2.0 to render all the pages in the site as Transitional, while rendering the special page as Strict. Setting the xhtmlConformance option as bellow in the system.web section - will render all controls and pages as Transitional.

<system.web>
   <xhtmlConformancemode="Transitional"/>
</system.web>

Since the main pages of the site are in the same root level directory - defining another web.config file for just the document.aspx wouldn't work.

Instead I used the location element (outside the <system.web> section). This will let you override any of the <system.web> settings for a specific location, directory or individual page.

<system.web>
   <xhtmlConformancemode="Transitional"/>
</system.web>

<locationpath="specialpage.aspx">
  <system.web>
   <xhtmlConformancemode="Strict"/>
 </system.web>
</location>

The hidden viewstate input element for the special page is now correctly wrapped in a <div> and the form name element no longer appears (just the ID).  The special page now passes for Strict while the rest of the site will pass for Transitional.

One last sneaky trick that took me a while to uncover - which could almost be consider a bug in ASP.Net - is that by default, with the default browser definition list - ASP.Net 2.0 doesn't recognise the W3C Validator's user agent - and no matter what you do - will not render Strict pages correctly and therefore all validation attempts for Strict will fail.

The trick is here....

http://idunno.org/displayBlog.aspx/2005080101

I created an App_Browsers folder in the project - and placed the browser definition for the W3C validator from the site above in this folder. The W3C Validator service was then receiving correctly rendered pages and passing the special page as strict.

:-)