? ASP.Net is renaming my HTML element IDs and breaking my CSS

  • Thread starter Thread starter DeepDiver
  • Start date Start date
D

DeepDiver

If I add a DropDownList Web Control to my Web Form and set
id="DropDownList1", then when I build and execute the page, the ID gets
changed to id="_ctl1_DropDownList1". This breaks my CSS which is tied to the
tag ID. Why does ASP.Net do this? The ID is required to be unique, so I see
no advantage in it getting programmatically modified during the build.

I am using an external stylesheet and don't want to embed the style in the
tag. Is there anyway around this problem?

TIA!
 
I had the same problem ...

just change the #name to .name and used classes in stead..
 
Darren Clark said:
I had the same problem ...

just change the #name to .name and used classes in stead..

Thanks Darren,

I did think about that, but it seems stupid that we should have to change
our valid code. Why does ASP.Net even need to change the value of the ID
property? Is this going to continue with the Whidbey release of ASP.Net?
 
I think it renames the tags in this way to eliminate naming conflicts.
Think about a user control with a drop down control called MyDDL. If you
then include that user control ten times your ASPX page, the IDs will clash
unless they've been renamed in some way - i.e. the format ASP.NET uses,
[usercontrolname]_MyDDL etc..

Dan
 
Back
Top