Documentation for this section has not yet been entered.
When a Web server control is rendered as an HTML element, the id attribute of the HTML element is set to the value of the Control.ClientID property. The Control.ClientID value is often used to access the HTML element in client script by using the document.getElementById method. The ID is also often used in CSS rules to specify elements to style. For example, the following CSS style rule selects all span elements that have the id attribute value of ProductIDLabel and sets their background-color attribute to white:
Example
span#ProductIDLabel { background-color: white; }
ASP.NET provides multiple algorithms for how to generate the Control.ClientID property value. You select which algorithm to use for a control by setting its Control.ClientIDMode property. The algorithms are identified by the System.Web.UI.ClientIDMode enumeration values that are listed in the following table.
ClientIDMode.AutoID |
The Control.ClientID value is generated by concatenating the Control.ID values of each parent naming container with the Control.ID value of the control. In data-binding scenarios where multiple instances of a control are rendered, an incrementing value is inserted in front of the control's Control.ID value. Each segment is separated by an underscore character (_). This algorithm was used in versions of ASP.NET earlier than ASP.NET 4. |
ClientIDMode.Static |
The Control.ClientID value is set to the value of the Control.ID property. If the control is a naming container, the control is used as the top of the hierarchy of naming containers for any controls that it contains. |
ClientIDMode.Predictable |
This algorithm is used for controls that are in data-bound controls. The Control.ClientID value is generated by concatenating the Control.ClientID value of the parent naming container with the Control.ID value of the control. If the control is a data-bound control that generates multiple rows, the value of the data field specified in the System.Web.UI.WebControls.IDataBoundListControl.ClientIDRowSuffix property is added at the end. For the System.Web.UI.WebControls.GridView control, multiple data fields can be specified. If the System.Web.UI.WebControls.IDataBoundListControl.ClientIDRowSuffix property is blank, a sequential number is added at the end instead of a data-field value. Each segment is separated by an underscore character (_). |
ClientIDMode.Inherit |
The control inherits the System.Web.UI.ClientIDMode setting of its Control.NamingContainer control. |
The default value of Control.ClientIDMode for a page is ClientIDMode.Predictable. The default value of Control.ClientIDMode for a control is ClientIDMode.Inherit. Because the default for controls is ClientIDMode.Inherit, the default generation mode is ClientIDMode.Predictable. (However, if you use Visual Studio to convert a Web project to ASP.NETÂ 4 from an earlier version, Visual Studio automatically sets the site default to ClientIDMode.AutoID in the Web.config file.)
For more information, see ASP.NET Control Identification.