YouTip LogoYouTip

Prop Control Standard Uniqueid

## ASP.NET UniqueID Property The `UniqueID` property is a standard control property in ASP.NET. It retrieves the unique, hierarchically-qualified, automatically generated identifier for a server control. --- ## Definition and Usage The `UniqueID` property provides a unique identifier for a control on an ASP.NET page. ### How it differs from the `ID` property: * **`ID`**: This is the user-defined identifier assigned to a control in the markup or code-behind (e.g., `ID="button1"`). It is not guaranteed to be globally unique across the entire page if the control is nested inside naming containers. * **`UniqueID`**: This is a fully qualified identifier automatically generated by the ASP.NET runtime during page processing. It incorporates the `ID` of the control prefixed with the IDs of its parent naming containers (such as Master Pages, User Controls, Panels, or GridViews), separated by a delimiter (typically a dollar sign `$` or colon `:` depending on the .NET Framework version). This property is particularly important when you need to programmatically identify a control during postbacks or when working with dynamically created controls. --- ## Syntax ```vb ' Visual Basic Syntax Dim uniqueIdentifier As String = Control.UniqueID ``` ```csharp // C# Syntax string uniqueIdentifier = Control.UniqueID; ``` --- ## Code Example The following example demonstrates how to retrieve and display the `UniqueID` of an ASP.NET `Button` control when it is clicked. ```html <%@ Page Language="VB" %> ASP.NET UniqueID Property Example
``` --- ## Key Considerations ### 1. Naming Containers If a control is placed inside a naming container (a control that implements the `INamingContainer` interface, such as `asp:Repeater`, `asp:GridView`, or a custom User Control), its `UniqueID` will reflect this hierarchy. For example, if `button1` is placed inside a User Control with the ID `myUserControl`, its `UniqueID` will look like: `myUserControl$button1` ### 2. Difference between `UniqueID` and `ClientID` * **`UniqueID`**: Used primarily for server-side processing and postback data tracking. It uses the `$` character as a separator. * **`ClientID`**: Used for client-side scripting (JavaScript/CSS) in the rendered HTML document. It typically uses an underscore `_` as a separator (e.g., `myUserControl_button1`) to ensure compatibility with CSS selectors and JavaScript element lookups. ### 3. Read-Only The `UniqueID` property is **read-only**. You cannot manually assign a value to it; it is managed entirely by the ASP.NET lifecycle.
← Prop Control Standard VisibleProp Control Standard Parent β†’