XHTML Conformance in ASP.NET 2.0

The key purpose of my last post was to demonstrate how the ASP.NET web controls follow the Decorator pattern when it comes to rendering and how developers can hook into that to customize the rendered HTML.

The example I demonstrated made a Button control render XHTML conformant markup. My article applies to ASP.NET 1.1. However, one commenter pointed out an even easier approach if you are working with ASP.NET 2.0. You can simply set the xhtmlConformance elment in Web.config. For example:

<xhtmlConformance mode="Transitional"/>

Well, I am sure you’ll find other uses for the decorator technique I wrote about.

What others have said

Requesting Gravatar... Matthijs van der Vleuten Jan 19, 2006 12:04 PM
# re: XHTML Conformance in ASP.NET 2.0
According to the MSDN article you linked to, the default xhtmlConformance mode is Transitional. Thus, your example Web.config setting does not affect anything.
Requesting Gravatar... Haacked Jan 19, 2006 1:10 PM
# re: XHTML Conformance in ASP.NET 2.0
True. So it looks like there is nothing to do in ASP.NET 2.0. to get XHTML Transitional compliance. But you can use that setting to conform to XHTML strict.

It's even easier than easy.
Requesting Gravatar... klevo Jan 19, 2006 1:45 PM
# re: XHTML Conformance in ASP.NET 2.0
Since you didn`t know about the xhtmlConformance switch I assume you don`t know about this great article either: http://msdn.microsoft.com/asp.net/reference/design/default.aspx?pull=/library/en-us/dnaspp/html/aspnetusstan.asp

It deals with ASP.NET 2.0 and web standarts and it`s a must read.

btw, thanks for linking to my page. The only problem is that it`s in slovak, so nobody here will understand :)
Requesting Gravatar... klevo Jan 19, 2006 1:55 PM
# re: XHTML Conformance in ASP.NET 2.0
upps, I am sorry, that link is a little bit long. Hope you can do something about it.
Requesting Gravatar... jayson knight Jan 19, 2006 2:34 PM
# re: XHTML Conformance in ASP.NET 2.0
klevo: I usually use tinyurl.com for Microsoft links as they are usually quite long and you never know how sites will handle posting long links.

Also Haacked, your #FeedBack anchor doesn't appear to be working when I click on the comments link from your main page (i.e. I'm not taken directly to the comments).
Requesting Gravatar... Haacked Jan 19, 2006 3:40 PM
# re: XHTML Conformance in ASP.NET 2.0
Klevo, thanks for the URL. I'm printing it now. I added overflow:auto to the comments which should handle long urls a little better now.

Jayson, it turns out that named anchors are case sensitive. So I need to change the links to use #feedback and not #FeedBack. Doh!
Requesting Gravatar... Brian Jan 19, 2006 3:46 PM
# re: XHTML Conformance in ASP.NET 2.0
I wonder if there is a good way to use your decorator idea to get ASP.NET 1.1 to render attributes on ListItems in a RadioButtonList. I've used this code with mixed results:
http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet.webcontrols/msg/279b59a121f3cff1
This didn't even work as well for me:
http://aspnet.4guysfromrolla.com/articles/091405-1.aspx

It seems to me that you can't decorate the HtmlTextWriter because the attributes are ignored byt RenderItem() in the ListControl. But it sure would be purty if you could.
Requesting Gravatar... Haacked Jan 19, 2006 4:09 PM
# re: XHTML Conformance in ASP.NET 2.0
Hmmm. I'd have to look into this later. I think it should work, because eventually, under the hood, the methods of the control are going to call methods of the underlying HtmlTextWriter.

The thing is, you might have to dig under the hood using Reflector to see exactly what RenderItem is doing.
Requesting Gravatar... Milan Negovan Jan 20, 2006 12:27 PM
# re: XHTML Conformance in ASP.NET 2.0
In defense of the said Decorator *cough* I'd say it has more power for granular tweaking than the xhtmlConformance tag.

You set xhtmlConformance="Strict" and you hope the markup will be nice and pretty. That just doesn't happen. This is where the decorator gives you the edge.

So the two can live side by side: xhtmlConformance for general conformants, and the decorator---for clean markup addicts.

The article klevo pointed out has some fun lines, such as "Internet Explorer (the most popular Web browser in the history of the world)".
Requesting Gravatar... Mike Jul 10, 2006 12:55 AM
# paxil-na-obed.blogspot.com
Excellent website. Easy to find helpful information. Your web site is helpful. Very nicely done. Congratulations! paxil
Requesting Gravatar... Vincent Sep 16, 2006 4:18 PM
# paris-hilton-hot.blogspot.com
Looks good! Easy to find helpful information. I will be back! paris hilton
Requesting Gravatar... Omar Sep 19, 2006 5:15 AM
# ativan-lx.blogspot.com/
Hello! Your web site is helpful, good stuff. Nice site. Keep it up! ativan
Requesting Gravatar... Fritz Schennk Dec 04, 2006 4:54 PM
# re: XHTML Conformance in ASP.NET 2.0
There is a need in some situations to have 'strict' compliance - for example in AJAX, XML or IFrame applications of some schema. So your technique could be used to make sure that the form element does not have a name attibute!

I thought your posting was great!
Requesting Gravatar... Chris James Mar 13, 2007 7:25 AM
# re: XHTML Conformance in ASP.NET 2.0
Hi, I had a few problems with ASP.net 2.0 and the W3C Validator. I couldnt get it to validate XHTML Strict.

Turns out you have to do some tinkering to make ASP serve correct code to the validators

Explained here: http://www.dbsolutionsltd.com/BlogEntry.aspx?blogEntryID=2
Requesting Gravatar... Michael Jul 22, 2007 6:51 AM
# re: XHTML Conformance in ASP.NET 2.0
Hi, I have a problem with mode="Legacy".
In this case AJAX Extentions 1.0 doesn't work:
some scripts are not rendered.
If you change mode to 'Transitional' it works.

What do you have to say?

(will show your gravatar)
Please add 8 and 7 and type the answer here: