How do you get the ID of User Control in client script?

K

Ken Varn

I have created a User Control (ASCX) and I need to be able to do some
JavaScript on the HTML side on some controls that are in the User Control.
How do I get the ID of the Controls within a User Control? Asp.net appends
each control with the ID of the ASCX control. Some controls are in the
format of ParentID:ControlID, and others are in the format of
ParentID_ControlID. Is there some method in JavaScript to determine the
true ID of the control with the pre-pended ASCX ID?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 
S

Steve C. Orr [MVP, MCSD]

You must determine this on the server side using MyControl.ClientID.
Then pass this ID to your client side code so it can use it.
 
K

Ken Varn

Thanks for your reply, but I actually found a solution that works well for
me.

I basically set a JavaScript variable to <%=ID%>. Then, I have the base ID
of the User Control and can then append that to any controls IDs that I
reference in Script. The only thing that I don't understand is why some
controls have a colon :)) between the UserControl ID and the Child Control
ID, and other IDs use an underscore (_)? Is there any rhyme or reason to
this?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

Emailed = varnk
Domain = Diebold.com
-----------------------------------
Steve C. Orr said:
You must determine this on the server side using MyControl.ClientID.
Then pass this ID to your client side code so it can use it.
 
S

Steve C. Orr [MVP, MCSD]

That's why you need to get the ClientID, not just the ID.
The reason they get named such ways is all about naming containers.
Here's more info:
http://msdn.microsoft.com/library/d...l/vbtskreferencingcontrolsinwebformspages.asp




Ken Varn said:
Thanks for your reply, but I actually found a solution that works well for
me.

I basically set a JavaScript variable to <%=ID%>. Then, I have the base
ID
of the User Control and can then append that to any controls IDs that I
reference in Script. The only thing that I don't understand is why some
controls have a colon :)) between the UserControl ID and the Child Control
ID, and other IDs use an underscore (_)? Is there any rhyme or reason to
this?

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

Emailed = varnk
Domain = Diebold.com
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top