This is a migrated thread and some comments may be shown as answers.

ClientID and ID explanation

2 Answers 121 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
R2
Top achievements
Rank 1
R2 asked on 24 Dec 2008, 04:26 PM
Hello,

On page 71 on the RadControlsAJAXCourseware.pdf, it introduces the ClientID and ID properties.  I need more understanding on this.  I understand the ID property of a control, but somehow the info on this page is a little confusing to me.  Now, I noticed that this topic must be a challenging one because further down the page, a blog is listed offering more information. I'm reading the blog, but I'm still unclear as it speaks about NamingContainer (which I assume is Namespace) and other info that I'm not quite looking for right now.

To simply ask, could you tell me exactly what this means (bolded text)?
1)

In some cases, "RadMenu1" will be present, but $find("RadMenu1") will return null. A safer way to find your

RadControl is to use a server tag to output the control ClientID to the $find() method. We leave it up to the

RadControl to figure out the correct ClientID in case the control is nested within a master page or user

control and the ClientID wouldn't be what we expect:


2)

ID and ClientID

The

 

ID property of a control identifies an ASP.NET server control. The ID is only unique within

 

the current NamingContainer (page, user control, item template).


3)
The

 

ClientID property is unique within the entire page. The ClientID will be rendered with the

 

container control, an underscore

 

and the control ID. If "RadMenu1" is located directly on the

 

page the two properties would be:


 

ID: "RadMenu1"

 

 

ClientID: "RadMenu1"

 

If "RadMenu1" is located in a user control "WebUserControl1", the properties are:

 

ID: "RadMenu1"

 

 

ClientID: "WebUserControl1_RadMenu1"

 



Thanks,
R2

2 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 24 Dec 2008, 04:40 PM
Hello R2,

The text in bold means the following:

If we have the following control on the page:

[ASPX]

<telerik:RadMenu ID="RadMenu1" runat="server" />

And if we want to obtain a reference to the client-side control instance, then it is better to use

[Javascript]

$find("<%= RadMenu1.ClientID %>");

than

$find("RadMenu1");


This is because if RadMenu1 is placed inside another control, which implements the INamingContainer interface, the ClientID of the menu will not be the same as the server ID. The $find() Javascript method requires a valid (existing) ClientID in order to return the client-side control instance.

I hope this makes things more clear. If not, then please refer to the ASP.NET documentation regarding naming containers, what they are and what they do.

Best wishes,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
R2
Top achievements
Rank 1
answered on 09 Jan 2009, 04:06 PM
Thanks, I'll try what you said since I am still unclear...
Tags
Ajax
Asked by
R2
Top achievements
Rank 1
Answers by
Dimo
Telerik team
R2
Top achievements
Rank 1
Share this question
or