XHTML strict in ASP.NET 2.0

by Mads Kristensen 25. April 2006 06:12

If you ever tried to validate a web page to the W3C standards you might have experienced some differences between the code that is generated to your browser and the code that the validators see. That's because ASP.NET renders the page differently for newer browsers and older browser. The validator is considered an old browser and is therefore presented with legacy code from the server controls.

An ImageButton control renders a border attribute (border="0") when in legacy/old mode and a style attribute when in strict/new mode (style="border-width:0px;"). If your page's DOCTYPE is XHTML strict, the border attribute is not allowed and your page doesn't validate because of that.

While browsing the web.config documentation at MSDN, I stumbled upon a switch that overrules this different rendering. If you are sure you always want the server controls to be rendered in strict/new mode, just add this element to the web.config's <system.web> section:

<xhtmlConformance mode="Strict" />

I do not understand why the ASP.NET 2.0 compiler doesn't look in the DOCTYPE for this information. By adding the above code to the web.config you are telling ASP.NET the same information twice, which is bad.

* Only $4.95/month ASP.NET & Windows 2008 + IIS 7 Hosting! FREE SQL Included

Tags:

ASP.NET

Comments

3/13/2007 9:34:53 PM #

 Chris James

We came accross a problem where asp.net was serving old code to the validators, which made them not valid.

The way to fix it is by telling ASP how to serve the W3C Validator

How to do that is detailed at

www.dbsolutionsltd.com/BlogEntry.aspx

Chris James |

Comments are closed

About the slave

Mads Kristensen Mads Kristensen
Web developer at ZYB and founder of BlogEngine.NET. More...

LinkedIn ZYB Facebook Last.fm Twitter View Mads Kristensen's profile on Technorati

The Lounge

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008