Asp. NET control Id,clientid,uniqueid the difference

Source: Internet
Author: User

In general, the three are the same (no parent control)

ID: Gets or sets the programmatic identifier assigned to the server control.
The programmatic identifier assigned to the control. (Can be written)

Setting this property on a server control provides programmatic access to the properties, events, and methods of the server control. WEB developers can set this property by declaring the ID property in the opening tag of the ASP.

If the property is not specified (declaratively or programmatically) for the server control, a reference to the control can be obtained from its parent control's controls property. ( see below )

Attention
Including spaces in this property will result in an ASP. NET page parser error.

: gets a unique, hierarchical, qualified identifier for a server control. (Read only)
The fully qualified identifier of the server control.

This property differs from the ID property because the UniqueID property contains the identifier of the server control naming container. This identifier is automatically generated when a page request is processed.

This property is especially important for differentiating server controls that are contained in other duplicate data-bound server controls. Repeating controls include Repeater, DataList, and Datagridweb server controls (or any custom server controls that have duplicate functionality created at data binding) that act as the naming container for their child controls. This means that it creates a unique namespace for its child controls so that their ID property values do not conflict.
For example, if you include a Asp.netlabelweb server control in a Repeater server control and assign the Label control an ID property value of MyLabel, assign the MyRepeater ID property value to Repeater. If you bind Repeater data to a ArrayList object with three items, the UniqueID property produced by each instance of the Label server control is MyRepeater:ctl0:MyLabel, MYREPEATER:CTL1: MyLabel and MyRepeater:Ctl2:MyLabel are generated by connecting the ID value of the control and the UniqueID value of its parent control .

ClientID: Gets the server control identifier generated by ASP. (Read only)
The server control identifier generated by ASP.

Sometimes, you cannot assign a unique name to a control. For example, if the Repeater control contains a label control in one of its templates, an instance of the label control is rendered for each item in the Repeater control. When rendering multiple instances of a control, to prevent naming conflicts, ASP. NET automatically generates a unique ClientID value for each server control on the page. the ClientID value is generated by connecting the control's ID value and the UniqueID value of its parent control. if the ID value of the control is not specified, the automatically generated value is used. The individual parts of the generated ID are delimited by the underscore character (_).

Attention
The ClientID value generated for the control is the same as the UniqueID value, except that the underscore character used to delimit the ID value is not the character specified by the Idseparator property . By default, the Idseparator property is set to the colon character (:). Because the ClientID value does not contain a colon character, it can be used for ECMAScript that do not support IDs that contain colons.

clientid values are often used to programmatically access HTML elements that are rendered for controls in client script. For more information, see Client-side Scripting in ASP.
Summary:
ID,
This must be familiar, for the server-side programming reference control, there is no corresponding client value, that is not rendered to HTML

UniqueID,
The ASP. NET engine is a hierarchical-qualified marker generated by the control tree hierarchy, and the connection defaults thinks $ (dollar sign) " Note: MSDN says the default is: (colon), actually $, maybe the document is wrong", This connector is represented in ASP. idseparator specifies that the Name property of the HTML element is rendered in the client
This property is primarily used to commit (PostBack) client data, such as Request.form[somecontrol.unqiueid]

ClientID, which is the ID of the parent control's Unqiueid connection itself. However, the connector is not the same, the default is    _ (underscore), this connector in ASP. clientidseparator , The id attribute that is rendered as an HTML element in the client,
This property is primarily used in the clients textbook, such as var o = document.getElementById (' <% = Somecontrol.clientid%> ');

With regard to the UniqueID hierarchy separator symbol, 1.x is: (colon), and 2.0 has been implemented as $ (dollar character), the main reason may be that the identifier in JavaScript is allowed $, and not allowed:. (When you're lazy, you can apply the form element directly in JS using the form element's name attribute instead of Document.getelementsbyname or document.getElementById, not recommended:)

Asp. NET control Id,clientid,uniqueid the difference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.