Click here to Skip to main content
11,709,536 members (50,584 online)
Click here to Skip to main content

ASP.NET Controls - Understanding ID Generation

, 5 Feb 2007 CPOL 20.9K 14
Rate this:
Please Sign up or sign in to vote.
An article about how IDs are generated and why they can increase the network bandwidth.


Any reader of this article should have, at least once, looked at the source of an HTML page with a simple DataGrid or a UserControl and noticed the length of the 'id' and 'name' attributes. The purpose of this articles is to understand the "How?" and "Why?" of them sometimes being really long.


These attributes are always unique, and therefore isn't a surprise saying that they are the visible face of the control server-side property called UniqueID.

The Control is the base class for all WebControls, and supplies three ID properties:

  • ID - Which can be set by the programmer.
  • UniqueID - A generated read-only ID used for server-side and postdata management. This property renders the attribute 'name'.
  • ClientID - A special read-only transformation of UniqueID for client-side exclusive purposes. This property renders the attribute 'id'.

A systemic analysis of Control code shows that the ClientID value is a UniqueID value transformation, and this last one is a composition of its NamingContainer.ID and its own ID.

This relation between properties shows us that it's possible to manage both 'id' and 'name' attributes through a simple manipulation of the server-side property ID of all the involved controls.

A potential problem

We should have in mind that almost all corporate ASP.NET solutions require high customization levels and therefore a reasonable number of composite custom controls. Those custom controls are heavily used and increase the parent hierarchy depth significantly. In addition, we cannot forget:

  • that naming business entities isn't as simple as that;
  • that a name that fully describes the intended functionality will substantially increase the readability and maintainability of code (are we ready to pay this price to simply minimize our pages size?);
  • the amazing naming creativity that a programmer is capable of.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nuno M. F. Gomes
Software Developer (Senior)
Portugal Portugal
Nuno Gomes currently works as a Senior Developer for one of the major portuguese banks.

Gomes graduated from Instituto Superior Tecnico with a Electronics and Computers degree in 1999.

His daily work main focus is, since 2003, on ASP.NET. A true .NET developer with great passion for the simple solution.

You may also be interested in...

Comments and Discussions

GeneralDotfuscator Pin
dapoussin5-Feb-07 21:31
memberdapoussin5-Feb-07 21:31 
GeneralRe: Dotfuscator Pin
Nuno M. F. Gomes6-Feb-07 12:49
memberNuno M. F. Gomes6-Feb-07 12:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 5 Feb 2007
Article Copyright 2007 by Nuno M. F. Gomes
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid