Control.ClientIDMode Control.ClientIDMode Control.ClientIDMode Control.ClientIDMode Property

定義

取得或設定用來產生 ClientID 屬性值的演算法。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; }
member this.ClientIDMode : System.Web.UI.ClientIDMode with get, set
Public Overridable Property ClientIDMode As ClientIDMode

屬性值

值,指定如何產生 ClientID 屬性 (Property)。A value that indicates how the ClientID property is generated. 預設為 InheritThe default is Inherit.

範例

下列範例所示Label中所包含的控制項ListView控制項。The following example shows Label controls that are contained in a ListView control. ListView控制項中,ClientIDMode屬性設定為PredictableClientIDRowSuffix屬性設定為ProductIDOn the ListView control, the ClientIDMode property is set to Predictable and the ClientIDRowSuffix property is set to ProductID. 在轉譯的 HTML,這會建立三個span對應至三個元素ProductIDLabel控制項。In the rendered HTML, this creates three span elements that correspond to three ProductIDLabel controls. 當頁面執行時,則id屬性span項目設為下列值: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.NET 提供如何產生多個演算法ClientID屬性值。ASP.NET provides multiple algorithms for how to generate the ClientID property value. 選取要設定控制項使用的演算法及其ClientIDMode屬性。You select which algorithm to use for a control by setting its ClientIDMode property. 演算法的識別方式ClientIDMode詳列於下表的列舉值。The algorithms are identified by the ClientIDMode enumeration values that are listed in the following table.

Value 描述Description
AutoID ClientID 值是透過串連每個父命名容器的 ID 值與控制項的 ID 值產生。The ClientID value is generated by concatenating the ID values of each parent naming container with the ID value of the control. 在呈現控制項之多個執行個體的資料繫結情節中,遞增值會插入控制項之 ID 值的前面。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 (). 這個演算法用於比 ASP.NET 4 還舊的版本。This algorithm was used in versions of ASP.NET earlier than ASP.NET 4.
Static ClientID 值設定為 ID 屬性的值。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. ClientID 值是透過串連父命名容器的 ClientID 值與控制項的 ID 值產生。The ClientID value is generated by concatenating the ClientID value of the parent naming container with the ID value of the control. 如果控制項是資料繫結控制項,並且會產生多個資料列,則 ClientIDRowSuffix 屬性中指定之資料欄位的值會加入結尾處。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. 針對 GridView 控制項,可以指定多個資料欄位。For the GridView control, multiple data fields can be specified. 如果ClientIDRowSuffix屬性空白的循序數字結尾處加入,而不是資料欄位值。If the ClientIDRowSuffix property is blank, a sequential number is added at the end instead of a data-field value. 這個數字在零處開始,並會加 1,每個資料列。This number begins at zero and is incremented by 1 for each row. 各區段是以底線字元 () 分隔。Each segment is separated by an underscore character ().
Inherit 此控制項會繼承其 ClientIDMode 控制項的 NamingContainer 設定。The control inherits the ClientIDMode setting of its NamingContainer control.

預設值ClientIDMode頁面是PredictableThe default value of ClientIDMode for a page is Predictable. 預設值ClientIDMode控制項是InheritThe default value of ClientIDMode for a control is Inherit. 因為控制項的預設值是Inherit、 模式會預設產生PredictableBecause the default for controls is Inherit, the default generation mode is Predictable. (不過,如果您使用 Visual Studio 將 Web 專案轉換成 ASP.NET 4 中,從較早版本時,Visual Studio 會自動將站台預設值設AutoIDWeb.config 檔案中。)(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.)

如需詳細資訊,請參閱 ASP.NET 網頁伺服器控制項識別For more information, see ASP.NET Web Server Control Identification.

適用於

另請參閱