Difference between ID, UniqueID, ClientID

In this post i will explain you the difference between RegularId, clientID, uniqueID properties in ASP.NET.

Regular ID:

Its a normal id that we would be giving to each control that we add to the page.

This ID is helpful for you to refer to the control in the code-behind (aspx.cs). For coding it on server side.

Unique ID:

Its a unique id for the control across the page. For example, assume that you have a user control in which you have one label. If you have added that user control twice on to the page, for two labels in two different user controls (UC1, UC2) we have the same ID known as “Label1″. But to differentiate between those two labels, ASP.NET maintains a unique ID for each label as “UC1$Label1″ and “UC2$Label1″. So Unique ID is a hierarchically qualified name. And the same thing would be assigned to the “name” property of the corresponding HTML tag. Here in the unique id, $ (dollar) character is used to separate the parent and child id.

Client ID:

Its also similar to unique id but it separates the parent and child ids using the _ (underscore) character. Then why we have this ClientID. The reason is that it would be assigned to the “id” attribute of the corresponding HTML tag on the client side. So if you want to access the control in the java script you can make use of Client ID property of a control.
Ex:
var label = document.getElementById(‘<%= Label1.ClientID%>’);

If you have added a label control onto the page then three properties of that label like ID, UniqueID, ClientID would be having the same value “Label1″.

If you want to explore more on this : go to here

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.