Id is changed on my server control! (_ctl5)

Discussion in 'ASP .Net' started by news.microsoft.com, Jul 15, 2004.

  1. I am sending the values from the servercontrol (HtmlSelect) by the method of
    GET and its anoying that ASP.NET changes the Id.

    Instead of this: <select id="_ctl5_language"> it should be <select
    id="language">.

    Any ideas.

    Thanks,
    Anders
     
    news.microsoft.com, Jul 15, 2004
    #1
    1. Advertising

  2. news.microsoft.com

    Teemu Keiski Guest

    Hi,

    ASP.NET changes the ID if your control is contained inside a naming
    container. It does this to provide guaranteed unique IDs to each and every
    control on the Page.

    In server-side code the original ID you gave works normally. You get the
    generated ID by using ClientID property of the control. However, with
    posting it doesn't seem to help. Best you can do is to name the container
    explicitly (now it seems that _ctl5 is autogenerated) and then determine the
    ID based on that and use that on the receiving Page.

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



    "news.microsoft.com" <> wrote in message
    news:...
    > I am sending the values from the servercontrol (HtmlSelect) by the method

    of
    > GET and its anoying that ASP.NET changes the Id.
    >
    > Instead of this: <select id="_ctl5_language"> it should be <select
    > id="language">.
    >
    > Any ideas.
    >
    > Thanks,
    > Anders
    >
    >
     
    Teemu Keiski, Jul 15, 2004
    #2
    1. Advertising

  3. If you use the control in a repeater, datalist or datagrid control it is
    normal to do this otherwise you will have more than one controls with one id

    Regards
    Martin

    "news.microsoft.com" <> wrote in message
    news:...
    > I am sending the values from the servercontrol (HtmlSelect) by the method

    of
    > GET and its anoying that ASP.NET changes the Id.
    >
    > Instead of this: <select id="_ctl5_language"> it should be <select
    > id="language">.
    >
    > Any ideas.
    >
    > Thanks,
    > Anders
    >
    >
     
    Martin Marinov, Jul 15, 2004
    #3
  4. "news.microsoft.com" <> wrote in message
    news:...
    > I am sending the values from the servercontrol (HtmlSelect) by the method

    of
    > GET and its anoying that ASP.NET changes the Id.
    >
    > Instead of this: <select id="_ctl5_language"> it should be <select
    > id="language">.


    Why did you want the ID to stay the same? Were you using Request.Form?
    Instead, get the value from the control - HtmlSelect.SelectedIndex.
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Jul 15, 2004
    #4
  5. Hi Teemu, thanks for the reply.

    I load the control in like this: skin = Page.LoadControl(skinPath);

    And as you say if I define the ID it will use that instead of _ctl5.
    Isnt there a way to avoid it from attaching itself to all the child
    controlds? (Well damnit you already gave me the answer on that)

    Best,
    Anders


    skin = Page.LoadControl(skinPath);
    "Teemu Keiski" <> wrote in message
    news:%...
    > Hi,
    >
    > ASP.NET changes the ID if your control is contained inside a naming
    > container. It does this to provide guaranteed unique IDs to each and every
    > control on the Page.
    >
    > In server-side code the original ID you gave works normally. You get the
    > generated ID by using ClientID property of the control. However, with
    > posting it doesn't seem to help. Best you can do is to name the container
    > explicitly (now it seems that _ctl5 is autogenerated) and then determine

    the
    > ID based on that and use that on the receiving Page.
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    > http://blogs.aspadvice.com/joteke
    >
    >
    >
    > "news.microsoft.com" <> wrote in message
    > news:...
    > > I am sending the values from the servercontrol (HtmlSelect) by the

    method
    > of
    > > GET and its anoying that ASP.NET changes the Id.
    > >
    > > Instead of this: <select id="_ctl5_language"> it should be <select
    > > id="language">.
    > >
    > > Any ideas.
    > >
    > > Thanks,
    > > Anders
    > >
    > >

    >
    >
     
    news.microsoft.com, Jul 15, 2004
    #5
  6. Hi John,

    The ID is visible in the URL once a post has been made so I want it to look
    nice.

    Also in order to avoid the viewstate info I am sending the values back thus
    using Request.Form.

    "John Saunders" <> wrote in message
    news:...
    > "news.microsoft.com" <> wrote in message
    > news:...
    > > I am sending the values from the servercontrol (HtmlSelect) by the

    method
    > of
    > > GET and its anoying that ASP.NET changes the Id.
    > >
    > > Instead of this: <select id="_ctl5_language"> it should be <select
    > > id="language">.

    >
    > Why did you want the ID to stay the same? Were you using Request.Form?
    > Instead, get the value from the control - HtmlSelect.SelectedIndex.
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
     
    news.microsoft.com, Jul 15, 2004
    #6
  7. "news.microsoft.com" <> wrote in message
    news:...
    > Hi John,
    >
    > The ID is visible in the URL once a post has been made so I want it to

    look
    > nice.
    >
    > Also in order to avoid the viewstate info I am sending the values back

    thus
    > using Request.Form.


    Request.Form has nothing to do with avoiding ViewState. I suggest you take a
    look at the value of SelectedIndex. You'll find that it has the same value
    you're looking for in Request.Form.
    --
    John Saunders
    johnwsaundersiii at hotmail

    > "John Saunders" <> wrote in message
    > news:...
    > > "news.microsoft.com" <> wrote in message
    > > news:...
    > > > I am sending the values from the servercontrol (HtmlSelect) by the

    > method
    > > of
    > > > GET and its anoying that ASP.NET changes the Id.
    > > >
    > > > Instead of this: <select id="_ctl5_language"> it should be <select
    > > > id="language">.

    > >
    > > Why did you want the ID to stay the same? Were you using Request.Form?
    > > Instead, get the value from the control - HtmlSelect.SelectedIndex.
    > > --
    > > John Saunders
    > > johnwsaundersiii at hotmail
    > >
    > >

    >
    >
     
    John Saunders, Jul 15, 2004
    #7
    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. Matthew Louden
    Replies:
    1
    Views:
    7,115
    Scott M.
    Oct 11, 2003
  2. Valerian John
    Replies:
    6
    Views:
    5,186
    Valerian John
    May 17, 2004
  3. Replies:
    1
    Views:
    744
    Rosanne
    Oct 11, 2005
  4. Steve Steve

    _ctl5:_ctl0:p1456 in webform textbox

    Steve Steve, Feb 18, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    171
    Alessandro Zifiglio
    Feb 19, 2004
  5. mxbrunet
    Replies:
    1
    Views:
    250
Loading...

Share This Page