Unique ID changing between postbacks!

J

John

I have an asp.net control which on the first Load of the page has a
unique ID something like:

_ctl0__ctl1_GroupName__ctl1_ControlName

and after the first postback it changes to:

_ctl0__ctl1_GroupName__ctl0_ControlName

which is very bad, because I'm using javascript which relies on the
unique id not changing between postbacks. If anyone has any ideas on
why that's changing, I'd really appreciate it. I know how asp.net sets
the unique id up to _ctl0__ctl1_GroupName_ but i don't know where it's
deciding the ctl0 or ctl1 part of it.


Thanks!
 
B

bruce barker

if you do not give a control an id, its assigned based on its index in its
parents collection. in your case the control is nested four deep, with only
one (GroupName) assigned a name. the name changes because between postbacks
you are changing the number of controls. you should not hardcode this names
in javascript, but rather register client script with the controls uniqueid.

-- bruce (sqlwork.com)


| I have an asp.net control which on the first Load of the page has a
| unique ID something like:
|
| _ctl0__ctl1_GroupName__ctl1_ControlName
|
| and after the first postback it changes to:
|
| _ctl0__ctl1_GroupName__ctl0_ControlName
|
| which is very bad, because I'm using javascript which relies on the
| unique id not changing between postbacks. If anyone has any ideas on
| why that's changing, I'd really appreciate it. I know how asp.net sets
| the unique id up to _ctl0__ctl1_GroupName_ but i don't know where it's
| deciding the ctl0 or ctl1 part of it.
|
|
| Thanks!
|
 
J

John

Thanks Bruce,

I do give the control an id, which is where it puts ControlName in:
_ctl0__ctl1_GroupName__ctl0_ControlName

And I am registering it on the client side. Which is the problem.
Here's the situation:

I have, lets say, an asp.net button, and I don't want to wait for the
postback to handle it. So I register a client side script which says
when this button is pushed, store a value in a list, along with it's
uniqueid(actually clientid, because html doesn't like colons). Then
when i do the postback, right away check to see if that list contains
anything, and if it contains this buttons unique id, look at the value,
and gather the information.

This works on every other page I use, but for some reason somethings
changing on this one that causes it's fully qualified ID to change.
 
J

John

Wow, thanks Bruce. It was a webuser control that I had as a sub
control, which didn't have it's ID explicitly set.. now everything is
back to normal... thank you very much!!
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top