Id is changed on my server control! (_ctl5)

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
 
T

Teemu Keiski

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

Martin Marinov

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
 
J

John Saunders

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

news.microsoft.com

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);
 
N

news.microsoft.com

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

John Saunders

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.
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top