views:

60

answers:

3

ASP.Net controls (e.g. asp:Label) generate messy html ids (e.g. ct100_ct100_Yabba_Dabba_Doo_FinallyTheRealId). Yeah, they're ugly, but someone told me today that they're also:

  1. unfriendly for SEO
  2. increase the page size

I half believe 1) and half disbelieve. I know that certain id names (e.g. "header") are keywords that search engines will use to generate meta information, but I'm more skeptical that a span with id="author" really affects SEO. I'm willing to admit that I could be wrong.

On point 2), I'm at least 90% skeptical. Most of page size is not the html characters and I truly wonder if 100 longer ids would even add 1kb to a page size.

I can go with one of two approaches. Which approach would you take?

Approach 1)

<asp:Label id="lblAuthor" runat="server"></asp:Label>

with code behind

protected void Page_Load(object sender, EventArgs e)
{
   lblAuthor.Text = "Superman";

or Approach 2)

<span id="author"><%# Eval("Author") %></span>

with code behind

public string Author { get; private set; }
protected void Page_Load(object sender, EventArgs e)
{
       Author = "Superman";

On the one hand, 1) doesn't generate the nasty ids. On the other hand, I've always hated untyped strings in asp.net web forms and avoided them when I can. Also, if a page has 30+ elements, I end up with 30 page properties, which makes me feel uneasy. (Side note: a reason to love how the model works in the MVC pattern).

We're working in .Net 3.5.

What are your thoughts?

Thanks.

+4  A: 

Approach 3)

<span id="author"><asp:Literal id="author" runat="server" /></span>

Code behind:

author.Text = "Dr. Seuss";

asp:Literal is what the name implies, a control that renders only the text you send it; no more, no less.

Anthony Pegram
Both you and Mathieu submitted essentially the same answer at about 1 minute apart. I'm giving you the points, because yours came first. I did give click up both answers.
John
+2  A: 

Approach 3)

<span id="author"><asp:Literal id="litAuthor" runat="server" /></span>

with code behind

protected void Page_Load(object sender, EventArgs e)
{
   litAuthor.Text = "Superman";
}

this solves you id problem with Labels. For other elements, good luck ;)

mathieu
+1  A: 

SEO: No

Page size - SURE. I mean, the strings are longer, so they take more space, so page size if longer.

Update to .NET 4.0 then you can override the ID's with stable short ID's.

TomTom
Any evidence, such as article links on your "SEO:No"? As to the second point, as soon as we're on IIS 7, to heck with web forms I'm pushing for MVC.
John