XHTML Conformance in ASP.NET 2.0

0 comments suggest edit

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.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

15 responses

  1. Avatar for Matthijs van der Vleuten
    Matthijs van der Vleuten January 19th, 2006

    According to the MSDN article you linked to, the default xhtmlConformance mode is Transitional. Thus, your example Web.config setting does not affect anything.

  2. Avatar for Haacked
    Haacked January 19th, 2006

    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.

  3. Avatar for klevo
    klevo January 19th, 2006

    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 :)

  4. Avatar for klevo
    klevo January 19th, 2006

    upps, I am sorry, that link is a little bit long. Hope you can do something about it.

  5. Avatar for jayson knight
    jayson knight January 19th, 2006

    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).

  6. Avatar for Haacked
    Haacked January 19th, 2006

    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!

  7. Avatar for Brian
    Brian January 19th, 2006

    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.

  8. Avatar for Haacked
    Haacked January 19th, 2006

    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.

  9. Avatar for Milan Negovan
    Milan Negovan January 20th, 2006

    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)".

  10. Avatar for Mike
    Mike July 9th, 2006

    Excellent website. Easy to find helpful information. Your web site is helpful. Very nicely done. Congratulations! paxil

  11. Avatar for Vincent
    Vincent September 16th, 2006

    Looks good! Easy to find helpful information. I will be back! paris hilton

  12. Avatar for Omar
    Omar September 18th, 2006

    Hello! Your web site is helpful, good stuff. Nice site. Keep it up! ativan

  13. Avatar for Fritz Schennk
    Fritz Schennk December 4th, 2006

    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!

  14. Avatar for Chris James
    Chris James March 12th, 2007

    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.c...

  15. Avatar for Michael
    Michael July 21st, 2007

    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.