ASP.NET and XHTML

2008-04-30


Why XHTML ?

XHTML is a World Wide Web Consortium (W3C) standard that defines HTML as an XML document. Creating Web pages that are conformant with XHTML standards has several advantages:

*      It guarantees that the elements in the pages are well formed. *      Because many browsers are increasingly moving toward supporting XHTML, creating pages that conform to XHTML standards helps ensure that your pages render consistently in all browsers. *      Using XHTML helps to make pages conform more readily to accessibility standards. *      XHTML is extensible, allowing the definition of new elements. *      An XHTML page is much easier to read programmatically for situations in which the Web page is processed by a computer instead of being read by users, and the document can be manipulated using transformations.

http://msdn2.microsoft.com/en-us/library/exc57y7e(vs.80).aspx

This page is specific to Microsoft Visual Studio 2005/.NET Framework 2.0

The W3C has identified several levels of XHTML conformance: XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.0 Strict, and XHTML 1.1. The XHTML 1.1 specification is the strictest of these levels.

For more information about the XHTML standard, see the specification for the Second Edition of XHTML 1.0 on the W3C Web site.(http://www.w3.org/)

**How to: Configure XHTML Rendering in ASP.NET Web Sites **

By default, when you are working with browsers that support at least HTML 4.0, ASP.NET pages and controls render markup that conforms to the XHTML 1.0 Transitional standard. However, you might want ASP.NET to render markup that conforms to the stricter XHTML 1.0 Strict specification. Conversely, you might want ASP.NET to render markup that does not conform to XHTML 1.0 Transitional specifications. This is typically true when you have existing pages that rely on tags or attributes that were supported in earlier versions of ASP.NET but do not conform to XHTML standards, such as rendering a name attribute in the form tag.

You can configure your Web site to render markup in three ways:

*   Legacy (which is similar to how markup was rendered in previous versions of ASP.NET) *   Transitional (XHTML 1.0 Transitional) *   Strict (XHTML 1.0 Strict)

Legacy is for render ASP.NET page markup that does not conform to XHTML, Transitional and Strict are for conforming ASP.NET pages to XHTML

o configure XHTML rendering in an ASP.NET Web site

* Under the system.web element in your application's Web.config file, add an xhtmlConformance element, and then set the mode attribute to Legacy, Transitional, or Strict. If no xhtmlConformance element is defined in the Web.config file, the default setting mode is transitional.

The following code example shows part of a Web.config file in which XHTML rendering is disabled.

<system.web> <!-- other elements here --> <xhtmlConformance mode="Legacy" /> </system.web>

The following code example shows part of a Web.config file in which XHTML 1.0 Strict rendering is specified.

<system.web> <!-- other elements here --> <xhtmlConformance mode="Strict" /> </system.web>


Other ways:

http://www.charon.co.uk/content.aspx?CategoryID=28&ArticleID=53