Why are my HTML element ID's getting renamed?

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

Teemu Keiski

Hi,

it is the convention ASp.NET uses to ensure that controls are uniquely named
on the page. The DDL is probably inside some type of container, perhaps user
control?

Anyway, you can get the rendered ID with ClientID property of the control
instance, so basically you could output this to the stylesheet from
server-side (sounds ugly though), the another might be using pure CSS
classes which work fine and which you can assign via control's CssClass
property/attribute.
 
C

cld

Hi,

it is the convention ASp.NET uses to ensure that controls are uniquely named
on the page. The DDL is probably inside some type of container, perhaps user
control?

Anyway, you can get the rendered ID with ClientID property of the control
instance, so basically you could output this to the stylesheet from
server-side (sounds ugly though), the another might be using pure CSS
classes which work fine and which you can assign via control's CssClass
property/attribute.
It is one of many things that MS did not think about in designing the
client side. It is not necessary to have unique ids, it is only
necessary to be able to map the positional stuff in the form or
querystring to the fields in the server; there are problems with radio
and chackbox fields. They have to be treated first.
 
F

Fritz

cld said:
It is one of many things that MS did not think about in designing the
client side. It is not necessary to have unique ids, it is only
necessary to be able to map the positional stuff in the form or
querystring to the fields in the server; there are problems with radio
and chackbox fields. They have to be treated first.
The only way I know to insure that your controls are named the way you want,
you must implement a naming interface (at the moment I don't remember what
interface).
 

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,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top