Id is changed on my server control! (_ctl5)

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

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
 
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.
 
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 said:
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.
 
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);
 
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.
 
news.microsoft.com said:
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.
 
Back
Top