Home > View Post

XHTML in .NET 2.0

With the release of ASP.NET 2.0 I am happy to report that support for XHTML has been improved immensely. By default ASP.NET 2.0 targets the XHTML 1.0 Transitional schema, but the purists amongst us might want to go for XHTML 1.0 Strict, or even XHTML 1.1 Strict. To make sure that your pages conform with the strict standards it is necessary to specify the following in the web.config file (inside the system.web node):

<xhtmlConformance mode="Strict"/>

This removes the name attribute from the form which is invalid in the stricter XHTML versions. However, this alone does not guarantee that the code produced is XHTML compliant. For example, the image server control does not render the alt attribute if the AlternateText property contains an empty string. To fix this, simply set the GenerateEmptyAlternateText property to make sure that an empty alt attribute is rendered:

image.GenerateEmptyAlternateText = true;

Which results in the desired <img src="..." alt="" />.

Hopefully this will get you one step further to XHTML compliance! Also, be sure to check out this article by Dino Esposito which explains how the ASP.NET server controls have improved in respect to XHTML conformance amongst other things.

Tags: ASP.NET

 
Bruusi Post By Bruusi
3:36 AM
21 Nov 2005

» Next Post: Failed to map the path App GlobalResources
« Previous Post: Better understand Cookies with ieHTTPHeaders

Comments are closed for this post.

© 2005 - 2017 Josh Twist - All Rights Reserved.