Jeff Lynch [MVP]

Sponsors

The Lounge

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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


Posted 05-02-2008 5:05 PM by Jeff Lynch
Filed under: ,

[Advertisement]

Comments

ignu wrote re: ASP.NET "Head" Rendering Issues!
on 05-02-2008 7:59 PM

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.

Ken Egozi wrote re: ASP.NET "Head" Rendering Issues!
on 05-03-2008 2:05 AM

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

Jeff Lynch wrote re: ASP.NET "Head" Rendering Issues!
on 05-03-2008 8:06 PM

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

Tim Vasil's Blog wrote Take total control over the head tag in ASP.NET
on 10-22-2008 2:46 AM

Take total control over the head tag in ASP.NET

Add a Comment

(required)  
(optional)
(required)  
Remember Me?