ASP.NET’s attempt at valid XHTML
I’m a .NET newbie. I’m learning the basics from a book that is really a lengthy ASP.NET tutorial. So far, so good.
Putting my web developer’s hat on, I am disappointed by the mark-up produced by .NET controls. It doesn’t validate. Take the following code:
<form runat="server">
<asp:Button id="button" runat="server" OnClick="button_Click" Text="Click Me" />
<asp:Label id="messageLabel" runat="server" />
</form>
It produces the following mark-up:
<form name="ctl00" method="post" action="ClickEvent.aspx" id="ctl00">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE4Nzk4Mzk1MzRkZAYY+czHhSGkOW9gO8GqxURPVBeZ" />
</div>
<input type="submit" name="button" value="Click Me" id="button" />
<span id="messageLabel"></span>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLVuv2KBwLz9r7ABPTBiD6bHah0G6B4fEICXl+rcO/V" />
</div></form>
There are a number of issues:
- The
formtag’snameattribute is deprecated in XHTML. - The ViewState value is encryped in a hidden
inputtag, which is wrapped in aDIVin order to make it validate. This extra HTML is plain nasty. It goes against what web standards promotes, i.e. clean, semantic mark-up.
Possible Solutions
“Intercept the HTML code before it is sent to the web browser” – The Code Project, Sep 2004.
I’m sure there’s a few more ways of getting ASP.NET to generate HTML but as I am humble beginner I’ll stop looking for now and post update when I’ve found them.



I’ve been developing asp.net applications since 2002. two years ago i really started getting into standards based design. i struggle with asp.net every single day. I often wonder if the creators of asp.net even know what the w3c is. Nevertheless even looked at the HTML 4.0.1 specification. I just blogged about the more recent issues i faced here: http://3cords.org/blogs/intelligentdesign/default.aspx
cmv
February 2, 2007
I don’t sure but this can be useful for you.
http://www.asp.net/cssadapters/
Seree
August 4, 2007