8.28.2012

UniqueID vs ClientID

Difference between UniqueID and ClientID

S.No UniqueID ClientID
1
Meaning:
UniqueID is also a uniquely identifiable ID for a control but only used by ASP.Net page framework to identify the control.

i.e., UniqueID = HTML's name attribute
Meaning:
ClientID is a unique ID string that is rendered to the client to identify the control in the output HTML.

i.e., ClientID = HTML's id attribute
2
Delimiter used:
It uses $ to include parent controls (container) ID to make it unique.

For example, ct100$ContentPlaceHolder1$txtLogin
Delimiter used:
It uses _ to include parent controls (container) ID to make it unique.

For example, ct100_ContentPlaceHolder1_txtLogin.
3
UniqueID Generation:
Similar to ClientID, UniqueID is also generated by appending the parent container's(parent control) ID with the original control id but with $ delimiter
ClientID Generation:
The client id for control will be generated by appending the parent container's(parent control) ID with the original control id with "_" as delimeter. In our example, ContentPlaceHolder1 is the ContentPlaceHolder ID of the master page which is the parent container for txtLogin.
4
How to get UniqueID of a control ?
For example, use txtLogin.UniqueID for ct100$ContentPlaceHolder1$txtLogin
How to get CientID of a control ?
For example, use txtLogin.ClientID for ct100_ContentPlaceHolder1_txtLogin.
5
Where to use ?
The unique id is used by the ASP.NET framework to identify the control when the page is posted back to the server.

i.e., UniqueID is used for server-side
Where to use ?
The client id can be used to identify the control in client side scripting like javascript.

i.e., ClientID is used for client-side

Note:
ClientID = HTML's id attribute and so when doing getElementById, we should always give the ClientId.
Instead, if we give UniqueID i.e., getElementById(Element's name), FireFox will fail.

2 comments:

  1. It is really a great work and the way in which u r sharing the knowledge is excellent.Thanks for helping me to understand basic concepts. As a beginner in Dot Net programming your post help me a lot.Thanks for your informative article. Dot Net Training in chennai | Dot Net Training institute in velachery

    ReplyDelete
  2. Given so much information in it. its very useful .perfect explanation about Dot net framework.Thanks for your valuable information. Dot Net Training in chennai | Dot Net Training institute in velachery

    ReplyDelete