When you declare an ID attribute on a Web server control to provide programmatic access to that control, the ASP.NET page framework automatically ensures that the ID you declare will be unique across your entire ASP.NET Web application.
The Naming Container
The ASP.NET page framework provides your applications with automatic control ID resolution through the
The classes that implement INamingContainer include:
The
Name Resolution in Data-Binding Scenarios
The automatic naming resolution provided by the page framework becomes important in data-binding scenarios. Consider the following example, which shows controls declared on a page.
When the MyLabel
to each instance. The page framework does this by using the fully qualified UniqueID property for each control. For example, the following code generates three versions of the Label control and writes their UniqueID property values to the page.
When this page is requested, it writes the following to the page:
-
The naming container of the Repeater control named
MyDataList
. This naming container depends upon the name given to the .aspx file.Note
If the .aspx file for this example were MySample1.aspx, the class of the naming container would be
ASP.mysample1_aspx
, but the naming container would bePage
. -
The instance of the next control that serves as a naming container, namely the Repeater control. This container name is displayed with its entire namespace qualifier.
-
The UniqueID property of each Label control inside the Repeater control.
Note
Do not write code that references controls using the value of the generated UniqueID property. You can treat the UniqueID property as a handle (for example, by passing it to a process), but you should not rely on it having a specific structure.