Why are my HTML element ID's getting renamed?

Discussion in 'ASP .Net Web Controls' started by DeepDiver, May 21, 2004.

  1. DeepDiver

    DeepDiver Guest

    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!
    DeepDiver, May 21, 2004
    #1
    1. Advertising

  2. DeepDiver

    Teemu Keiski Guest

    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" <> wrote in message
    news:...
    > 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!
    >
    >
    Teemu Keiski, May 21, 2004
    #2
    1. Advertising

  3. DeepDiver

    cld Guest

    In article <>,
    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.
    cld, Jun 4, 2004
    #3
  4. 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" <> wrote in message
    news:...
    > In article <>,
    > 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.
    Alvin Bruney [MVP], Jun 5, 2004
    #4
  5. DeepDiver

    Fritz Guest

    cld wrote:

    > In article <>,
    > 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).
    Fritz, Jun 18, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Evgeny Zoldin

    New Project as renamed and chaged old one

    Evgeny Zoldin, Jul 4, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    508
    Evgeny Zoldin
    Jul 6, 2004
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    859
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,757
    Smokey Grindel
    Dec 2, 2006
  4. Abraham Luna

    why does the form id get renamed

    Abraham Luna, Sep 2, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    108
    Abraham Luna
    Sep 2, 2005
  5. Peter Bailey
    Replies:
    4
    Views:
    82
    Brian Candler
    May 16, 2007
Loading...

Share This Page