ערוך

שתף באמצעות


Control.ClientIDMode Property

Definition

Gets or sets the algorithm that is used to generate the value of the ClientID property.

public:
 virtual property System::Web::UI::ClientIDMode ClientIDMode { System::Web::UI::ClientIDMode get(); void set(System::Web::UI::ClientIDMode value); };
[System.Web.UI.Themeable(false)]
public virtual System.Web.UI.ClientIDMode ClientIDMode { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.ClientIDMode : System.Web.UI.ClientIDMode with get, set
Public Overridable Property ClientIDMode As ClientIDMode

Property Value

A value that indicates how the ClientID property is generated. The default is Inherit.

Attributes

Examples

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. In the rendered HTML, this creates three span elements that correspond to three ProductIDLabel controls. When the page runs, the id attributes for the span elements are set to the following values:

  • ListView1_ProductIDLabel_1
  • ListView1_ProductIDLabel_34
  • ListView1_ProductIDLabel_43
<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>

Remarks

ASP.NET provides multiple algorithms for how to generate the ClientID property value. You select which algorithm to use for a control by setting its ClientIDMode property. The algorithms are identified by the ClientIDMode enumeration values that are listed in the following table.

Value Description
AutoID The 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 was used in versions of ASP.NET earlier than ASP.NET 4.
Static The 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.
Predictable This 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. This number begins at zero and is incremented by 1 for each row. Each segment is separated by an underscore character (_).
Inherit The control inherits the ClientIDMode setting of its NamingContainer control.

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.)

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

Applies to

See also