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

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!
 
D

Darren Clark

I had the same problem ...

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

DeepDiver

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?
 
D

Dan

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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top