Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Why are my HTML element ID's getting renamed?

Reply
Thread Tools

Why are my HTML element ID's getting renamed?

 
 
DeepDiver
Guest
Posts: n/a
 
      05-21-2004
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!


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      05-21-2004
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.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke



"DeepDiver" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!
>
>



 
Reply With Quote
 
 
 
 
cld
Guest
Posts: n/a
 
      06-04-2004
In article <(E-Mail Removed)>,
http://www.velocityreviews.com/forums/(E-Mail Removed) says...
> 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.
 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      06-05-2004
what makes you think MS did not think of it?

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"cld" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <(E-Mail Removed)>,
> (E-Mail Removed) says...
>> 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.



 
Reply With Quote
 
Fritz
Guest
Posts: n/a
 
      06-18-2004
cld wrote:

> In article <(E-Mail Removed)>,
> (E-Mail Removed) says...
>> 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.

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).

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
Conversion from a HTML element to table element vinayak Javascript 5 01-18-2008 10:08 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why does getting style.color or an element return nothing? pantagruel Javascript 1 08-24-2005 01:52 PM



Advertisments