473,466 Members | 1,286 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
-----------------------------------
Nov 19 '05 #1
3 3996
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.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Ken Varn" <nospam> wrote in message
news:eH**************@TK2MSFTNGP12.phx.gbl...
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
-----------------------------------

Nov 19 '05 #2
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 [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Ken Varn" <nospam> wrote in message
news:eH**************@TK2MSFTNGP12.phx.gbl...
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
-----------------------------------


Nov 19 '05 #3
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/de...formspages.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Ken Varn" <nospam> wrote in message
news:u6**************@TK2MSFTNGP12.phx.gbl...
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 [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Ken Varn" <nospam> wrote in message
news:eH**************@TK2MSFTNGP12.phx.gbl...
>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
> -----------------------------------
>
>



Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: trinitypete | last post by:
Hi all, I have a user control that uses control literal to build a heading with a link, and a div containing links below. As the link heading is hit, I want to change the style of the div,...
0
by: Ron Vecchi | last post by:
Hello, Through using this and many other Microsoft dotnet newsgroups I have been pointed towards many helpful open source projects and articles that have helped a great deal in my studies as...
7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
6
by: KS | last post by:
I have made a WebForm with log ON/OFF off users. There is a label that shows the total count off users logged on stored in Application("UserCount") It works fine if the users logs out WITH THE...
5
by: vishesh vyas | last post by:
Hi All, I am having a user control consisting of few mandatory fields. How to validate these mandatory fields on the .aspx page submission? Thanks In Advance Regards, Vishesh
4
by: Barb | last post by:
I have a user control as my Save button for my page. When the Save button is clicked, I want some client-side validation to take place from a javascript function in the page, and then I'd like the...
10
by: sqlboy2000 | last post by:
Hello all, I have something very simple going on here and I'm scratching my head as to what the problem is. There are 4 items in my project, 2 webforms, a user control, and a module: ...
3
by: David Davis | last post by:
I cannot get a web user control to validation client-side using a required field validator. It only validates server side. I have a web user control in .net 2.0. I have a single text box on it....
7
by: Christian Cambier | last post by:
Hi, I have a textbox in a web user control. I then add the usercontrol to a web form. I also add a label in the web form. Now, when I press a key in the textbox, i want to display some text...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.