Control ids

S

Steve Peterson

Hello

Is there a way to change the id of an generated html of an asp.net control?
What I mean is that, for example, if I have an textbox control and give it
an id of "txtName", the html generated is something like:
id="_ctl2_txtName".

Apparently,according to our clients "search engine expert", the google
search algorithms penalize controls that have id's begining with an
underscore ( _ ). Since our client is a big fan of doing the "google dance"
and wants his site to be as far up in the search engine as possible, I need
to know if I can change the auto generated leading underscore to something
else..

Thanks ahead of time
Steve

PS Just out of curiosity - how many of you out there have had to increase
your develoment time and actually have to come up with pain in the butt
workarounds (thus tying your hands and using all the time saving things of
asp.net) to just to try and get you .aspx html to be "google" friendly? Just
curious - because I know I have..
 
K

Karl Seguin

As far as I know, there's no way to change the automatically generated ids,
short of explicitely assigning them. This can certainly be difficult in
some cases (such as repeaters/grids/lists) and probably almost impossible in
the case where literals (spaces/enters) are automatically converted to
controls.

For example, you can do:
private void rpt_ItemCreated(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
e.Item.ID = "row" + e.Item.ItemIndex;
}

in the ItemCreated event of a list/grid/repeater


Karl
 
L

Leon Mayne [MVP]

Steve said:
Is there a way to change the id of an generated html of an asp.net
control? What I mean is that, for example, if I have an textbox
control and give it an id of "txtName", the html generated is
something like: id="_ctl2_txtName".

Not as far as I know.

When I try it seems to set the id to the same as the name:
<input name="txtName" type="text" id="txtName" />&nbsp;
<input type="submit" name="btnOK" value="OK" id="btnOK" />

Not sure why yours is different
Apparently,according to our clients "search engine expert", the google
search algorithms penalize controls that have id's begining with an
underscore ( _ ).

I find that hard to believe. What is google going to index in a textbox? The
only references I can find on the web relating to Google and underscores is
that google can separate a phrase into words using hyphens but not
underscores (e.g. a file called my-file.html would be recognised as "my
file", but my_file.html wouldn't).
 
S

Steve Peterson

Thanks Leon

Well - you are correct:

<asp:TextBox id="txtName" runat="server"></asp:TextBox><br>
<asp:Button id="btnTest" runat="server" Text="Button"></asp:Button>

gives HTML:

<input name="txtName" type="text" id="txtName" /><br>
<input type="submit" name="btnTest" value="Button" id="btnTest" />

HOWEVER! If you put the same controls inside a web user control (like I'm
going) and place the web user control inside and .aspx page you get (at
least I do):

<input name="_ctl0:txtName" type="text" id="ctl0_txtName" /><br>
<input type="submit" name="_ctl0:btnTest" value="Button"
id="_ctl0_btnTest" />

The id is generated as to give it a uniqueid in the control collection...
(correct me if I'm wrong..)

As for our clients "search engine expert", I personally agree with you. I
think that the leading underscore for the id inside a well formed tag is
perfectly acceptable. I also find it hard to believe. Sigh...

Steve
 
I

intrader

Hello

Is there a way to change the id of an generated html of an asp.net control?
What I mean is that, for example, if I have an textbox control and give it
an id of "txtName", the html generated is something like:
id="_ctl2_txtName".

Apparently,according to our clients "search engine expert", the google
search algorithms penalize controls that have id's begining with an
underscore ( _ ). Since our client is a big fan of doing the "google dance"
and wants his site to be as far up in the search engine as possible, I need
to know if I can change the auto generated leading underscore to something
else..

Thanks ahead of time
Steve

PS Just out of curiosity - how many of you out there have had to increase
your develoment time and actually have to come up with pain in the butt
workarounds (thus tying your hands and using all the time saving things of
asp.net) to just to try and get you .aspx html to be "google" friendly? Just
curious - because I know I have..
As to your PS, we worried a lot in the earlier times of the net (1994).
Now we don't worry, but do what is required to 'satisfy' (to fake it)
Google.
 
L

Leon Mayne [MVP]

Steve said:
The id is generated as to give it a uniqueid in the control
collection... (correct me if I'm wrong..)

Sorry, I missed the fact you're using them in a user control. Yes, it would
be to make the instances of the control unique, and in this case I don't see
how you could control it at all, as allowing users to override the
incremental naming could cause problems.

It's a shame you can't specify a pattern for it to use as the prefix, such
as "ctlx-y" instead of "_ctlx_y".
As for our clients "search engine expert", I personally agree with
you. I think that the leading underscore for the id inside a well
formed tag is perfectly acceptable. I also find it hard to believe.
Sigh...

I just don't understand their logic. Presumably they are saying that the
problem is either:
1) Google won't index the text inside the control, or
2) Google will completely ignore the whole page if a control has an
underscore in the name

If the problem is 1, then who cares? There's presumably no extremely
important search terms inside the markup for the control? If they think the
problem is 2, then I'd have to say that's complete nonsense. I think you
should ask them to clarify their statement and send you evidence published
somewhere. They may go quiet then and the client will stop bugging you about
it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top