views:

817

answers:

6

So, my personal site is running on a custom blog engine that I wrote, and I'm really happy with it. However, it uses a master page, which means that ASP.NET prepends (for no good reason) 'ct100' to all of the id's...For example:

<div id='menu'>
   <ul>
    <li id="ctl00_homeTab" class="active"><a href="/">Home</a></li>
    <li id="ctl00_codeTab"><a href="/code/">Code / Projects</a></li>
    <li id="ctl00_aboutTab"><a href="/about/">About Me</a></li>
    <li id="ctl00_contactTab"><a href="/contact/">Contact</a></li>
  </ul>
</div>

I'd like to prettify the markup a bit, and strip these out, or at least rename them to something that makes more sense. Since Webforms is fairly pluggible, I'd imagine there is a way to do this. I know that the content placeholder is acting as a naming container, but in my case I'd just like to have a decent id, 'master' instead of 'ct100' would be a start.

While I'm being silly and anal, the other thing I'd like to do is fix the indentation of markup when using UserControls. If you take a look at my site you'll see that the user controls have no indentation and break the flow of the source. This probably can't be fixed without running the page output through a pretty printer...and that would be a waste of time.

Do not tell me to switch to MVC. I have already evaluated it, and will be sticking with Webforms.

+2  A: 

To be completely honest, I don't see the benefit of going through a lot of work for a minimal amount of markup beautification... although I admire your desire in some weird way.

Your site looks fine - put the effort into what's actually rendered in the browser and the features for the end users. :)

routeNpingme
+1  A: 

Those control prefixes are how ASP.NET finds controls on the page, for ... if I remember correctly ... viewstate / postback. I, too, hate these prefixes, but the JavaScript that ASP.NET generates requires them.

HardCode
A: 

I suppose you could hook up a ResponseFilter to prettify...good luck with the regexes. ;)

Mark Brackett
+2  A: 

Although proberly isnt of much use to you at this moment in time, the next realease of ASP .NET will allow you to have more control over the outputed id's of your controls.

Theres some good info on this blog post...

http://www.mostlylucid.net/archive/2008/11/03/way-too-much-information-on-control-ids-and-asp.net-4.0.aspx

Sean Taylor
I agree if it's your blog wait for asp.net 4
Aaron Fischer
A: 

CSS Friendly Control Adapters ? I use them in multiple projects and am quite happy with them. They even convert to 3.0, 3.5 nicely.

The menu adapter does exactly what you want.

Mcbeev
+1  A: 

Yes, you can do just this by using ASP .NET 2.0 Control Adapters. Control Adapters allow you to modify the way existing server controls output their code without having to change any code in your ASPX files. you can see how it is done here:

http://weblogs.asp.net/scottgu/archive/2006/11/29/tip-trick-use-the-asp-net-2-0-css-control-adapters-for-css-friendly-html-output.aspx

The adapters were ariginally design to allow easy use of CSS with .NET controls that redered Tables, but it can be used for your purposes just as well.

Russ Bradberry