Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
1 out of 1 rated this helpful - Rate this topic

ClientIDMode Enumeration

Specifies how ASP.NET generates the ClientID for a control that can be accessed in client script.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)
public enum ClientIDMode
Member nameDescription
AutoIDThe ClientID value is generated by concatenating the ID values of each parent naming container with the 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 ID value. Each segment is separated by an underscore character (_). This algorithm is the only one that was available in versions of ASP.NET earlier than ASP.NET 4.
InheritThe control inherits the ClientIDMode setting of its NamingContainer control.
PredictableThis algorithm is used for controls that are in data-bound controls. The ClientID value is generated by concatenating the ClientID value of the parent naming container with the 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 ClientIDRowSuffix property is added at the end. For the GridView control, multiple data fields can be specified. If the 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 (_).
StaticThe ClientID value is set to the value of the 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.

You use the ClientIDMode enumeration when you set the ClientIDMode property for a control. The value that you assign to the ClientIDMode property determines how the ClientID property is generated. The value of the ClientID property is rendered as the id attribute in markup, and it is the value that you use to access the control from client script. The value that you assign to the ClientIDMode property does not affect the ID property of the server control, only the id attribute of the corresponding HTML element.

The default value of ClientIDMode for a page is Predictable. The default value of ClientIDMode for a control is Inherit.

Because the default for controls is Inherit, the default generation mode is 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 AutoID in the Web.config file.)

You can set the ClientIDMode value for all pages in a Web site by setting the pages element in the site's Web.config file. You can set the ClientIDMode value for a page in the @ Page directive.

For more information, see ASP.NET Web Server Control Identification.

The following example shows Label controls that are contained in a ListView control. On the ListView control, the ClientIDMode property is set to Predictable and the ClientIDRowSuffix property is set to ProductID. From client script, you can access a particular instance of a Label based on the ProductID value of the instance that you are trying to access.

This example creates HTML with three ProductIDLabel controls. When the page runs, the IDs for the controls will be the following:

  • ListView1_ProductIDLabel_1

  • ListView1_ProductIDLabel_34

  • ListView1_ProductIDLabel_43

For more information, see ASP.NET Web Server Control Identification

<asp:XmlDataSource ID="XmlDataSource1" runat="server" 
                   XPath="Products/Product">
  <Data>
    <Products>
      <Product ProductID="1"  ProductName="Chai" />
      <Product ProductID="34" ProductName="Ale" />
      <Product ProductID="43" ProductName="Coffee" />
    </Products>
  </Data>
</asp:XmlDataSource>

<asp:ListView ID="ListView1" 
              ClientIDMode="Predictable" 
              ClientIDRowSuffix="ProductID"  
              DataSourceID="XmlDataSource1" runat="server" >
  <ItemTemplate>
    ProductID: 
    <asp:Label ID="ProductIDLabel" runat="server" 
               Text='<%# Eval("ProductID") %>' />
    <br />
    ProductName:
    <asp:Label ID="ProductNameLabel" runat="server" 
               Text='<%# Eval("ProductName") %>' />
    <br />
    <br />
  </ItemTemplate>

  <LayoutTemplate>
    <div ID="itemPlaceholderContainer" runat="server">
      <span ID="itemPlaceholder" runat="server" />
    </div>
    <div>
    </div>
  </LayoutTemplate>

</asp:ListView>

.NET Framework

Supported in: 4.5.1, 4.5, 4

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft. All rights reserved.