Click here to Skip to main content
15,886,110 members
Articles / Web Development / ASP.NET

ASP.NET Controls - Understanding ID Generation

Rate me:
Please Sign up or sign in to vote.
2.84/5 (21 votes)
5 Feb 2007CPOL1 min read 26.2K   14   2
An article about how IDs are generated and why they can increase the network bandwidth.

Introduction

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.

Background

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.

License

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


Written By
Architect everis
Portugal Portugal
Over 13 years of experience in the Software Development working mainly in the banking and insurance industry.

Over 3 year of experience as Operations Team Leader focused on Infrastructure Management and Software Configuration Management.

I've been honored with the Microsoft Most Valuable Professional (MVP) Award for three consecutive years, 2010, 2011 and 2012, in recognition to exceptional technical contributions and leadership.

Current / Recent Technical Projects
- Dominican Republic Instance management, including 2nd line System management, capacity management, SW monitoring and deploy management
- Colombian SECOPII Instance management, including 2nd line System management, capacity management, SW monitoring and deploy management
- Vortal Main Instance management, including 2nd line System management, capacity management, SW monitoring and deploy management
- Vortal Development ecosystem management, including Server management, , capacity management, SW monitoring and deploy management

Areas of Specialization:
- Operations Management - ISO 20000 & ISO 27001 driven
- Team Management and Coaching
- Technology Leadership, Solutions/Architecture
- Product life cycle management, Continuous Integration
- Technological background in Microsoft frameworks and tools.

Comments and Discussions

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

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

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