ASP.NET "Head" Rendering Issues!

Are you one of “those” ASP.NET web developers that care passionately about not only about writing “good” code, but writing “easily” understood and “readable” code? Are you looked upon as perhaps a little bit “obsessive” about your code? Do you understand what “semantic” really means?


If the answer is yes, have you ever looked closely at the HTML markup your ASP.NET code generates? I mean taken a really, REALLY close-up look?


If you have and you’re anything like me, it bugs the hell out of you when adding something as simple as <head runat=”server”> produces this mess in the <head> of your otherwise beautiful HTML markup.



Of course, there are ways to fix this mess. You could always forget using Master Pages and code each .aspx page by hand or even write your own base-page class like I’ve seen done. You could even revert to using “static” .html pages with JavaScript and forget about all the great features .NET brings to web development. Or you could just forget about ever creating truly “semantic” HTML markup using ASP.NET!


However, if you Google (or Live Search) long enough, you’ll find a few posts about something called Adaptive Control Behavior in the MSDN Library and three very well hidden posts by Anatoly Lubarsky with some great sample code!


http://blogs.x2line.com/al/archive/2007/01/10/2773.aspx


http://blogs.x2line.com/al/archive/2007/01/31/2814.aspx


http://blogs.x2line.com/al/archive/2007/01/31/2816.aspx


These three posts and the sample code you can download here, turn this code …



into this markup …



which is exactly what the <head> element of any respectable HTML markup should look like! And yes, I know it doesn’t matter one hoot to the browser (even IE6) which will faithfully render the web page correctly, but IT MATTERS TO ME.


I use “View Source” and Firebug almost every day to look at my own markup as well as the markup of sites who’s authors I respect. I want my markup to look every bit as professional as the markup of a professional web “designer” such as Dan Cederholm, John Gruber or Andy Clarke.


Don’t you?


Currently listening to: “Caravan of Dreams” by Peter White

This entry was posted in ASP.NET, Web 2.0. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

5 Responses to ASP.NET "Head" Rendering Issues!

  1. Aaron says:

    Jeff,

    These control adapters rip anything out of the head that’s not a .NET control such as JavaScript tags, conditional comments, etc. This needs to be addressed before these can be widely used.

  2. Lee C. says:

    I think this is another example of a developer who means well, but does not get it. The tool that you use to view your page source should use local clock cycles to tidy the source–not the server. If your tool doesn’t do that, get a better one!

    I actually minify my page source for delivery to the browser–reducing white space, not adding it. You are sending a lot of extra white space characters across the wire with your server-tidied HTML.

    , Lee

  3. jlynch says:

    @Ken: I may not be able to get rid of the VIEWSTATE (since it actually contains the server controls “control state”) but I have found a few ways to minimize it and move it to the bottom of the page.

    @ignu: Hmmmm… I do obsess over my IL code. How did you guess? (LOL)

  4. Ken Egozi says:

    @ignu:
    Well, HTML markup is much different than IL.
    Why?
    ask any 13 yr. old web hacker.

    A web developer needs close interaction with the markup, when doing JS/CSS stuff, when poking around with FBug, etc. Poking around IL is not as common to say the least.

    @Jeff:
    Now all you have left is to get rid of that ridiculous VIEWSTATE field …

  5. ignu says:

    no, i don’t. this would be like obsessing over how pretty the IL of my assembly looked. it’s generated code, and doing any work to improve its output is too much work.

    control adapters can be really useful when the generated code is causing problems or bloat, but prettying up auto-generated formatting isn’t useful, imho.

Leave a Reply