INamingContainer 介面

定義

識別在 Page 物件的控制項階層架構內建立新 ID 命名空間的容器控制項。Identifies a container control that creates a new ID namespace within a Page object's control hierarchy. 這只是資料標記介面。This is a marker interface only.

public interface class INamingContainer
public interface INamingContainer
type INamingContainer = interface
Public Interface INamingContainer
衍生

範例

下列程式碼範例示範可實作為INamingContainer介面的樣板化自訂伺服器控制項。The following code example demonstrates a templated custom server control that implements the INamingContainer interface. 當這個自訂伺服器控制項用於 .aspx 檔案時, 它會為它所包含的任何伺服器控制項提供唯一的命名空間。When this custom server control is used in an .aspx file, it will provide a unique namespace for any server controls that it contains.

using System;
using System.Collections;
using System.Web;
using System.Web.UI;

namespace TemplateControlSamples {

    public class RepeaterItem : Control, INamingContainer {

        private int itemIndex;
        private object dataItem;

        public RepeaterItem(int itemIndex, object dataItem) {
            this.itemIndex = itemIndex;
            this.dataItem = dataItem;
        }

        public object DataItem {
            get {
                return dataItem;
            }
        }

        public int ItemIndex {
            get {
                return itemIndex;
            }
        }
    }
}
Imports System.Collections
Imports System.Web
Imports System.Web.UI

Namespace TemplateControlSamplesVB

    Public Class RepeaterItemVB : Inherits Control : Implements INamingContainer

        Private _ItemIndex As Integer
        Private _DataItem As Object

        Public Sub New(ItemIndex As Integer, DataItem As Object)
            MyBase.New()
            _ItemIndex = ItemIndex
            _DataItem = DataItem
        End Sub

        Public ReadOnly Property DataItem As Object
            Get
                return _DataItem
            End Get
        End Property

        Public ReadOnly Property ItemIndex As Integer
            Get
                return _ItemIndex
            End Get
        End Property

    End Class

End Namespace

備註

任何會執行此介面的控制項都會建立新的命名空間, 其中所有的子控制項識別碼屬性在整個應用程式中都保證是唯一的。Any control that implements this interface creates a new namespace in which all child control ID attributes are guaranteed to be unique within an entire application. 這個介面所提供的標記允許在支援資料系結的 Web 服務器控制項內, 動態產生的伺服器控制項實例進行唯一的命名。The marker provided by this interface allows unique naming of the dynamically generated server control instances within the Web server controls that support data binding. 這些Repeater控制項包括、 DataGridSiteMapNodeItem、、 、、LoginView、和RadioButtonList控制項。 CheckBoxList ChangePassword DataList MenuThese controls include the Repeater, DataGrid, DataList, CheckBoxList, ChangePassword, LoginView, Menu, SiteMapNodeItem, and RadioButtonList controls.

當您開發樣板化控制項時, 您應該執行此介面來避免頁面上的命名衝突。When you develop templated controls, you should implement this interface to avoid naming conflicts on a page. 如需詳細資訊, 請參閱ASP.NET 控制項設計工具總覽For more information, see ASP.NET Control Designers Overview.

擴充方法

GetDefaultValues(INamingContainer)

取得所指定資料控制項的預設值集合。Gets the collection of the default values for the specified data control.

GetMetaTable(INamingContainer)

取得所指定資料控制項中的資料表中繼資料。Gets the table metadata for the specified data control.

SetMetaTable(INamingContainer, MetaTable)

設定所指定資料控制項中的資料表中繼資料。Sets the table metadata for the specified data control.

SetMetaTable(INamingContainer, MetaTable, IDictionary<String,Object>)

設定所指定資料控制項的資料表中繼資料及預設值對應。Sets the table metadata and default value mapping for the specified data control.

SetMetaTable(INamingContainer, MetaTable, Object)

設定所指定資料控制項的資料表中繼資料及預設值對應。Sets the table metadata and default value mapping for the specified data control.

TryGetMetaTable(INamingContainer, MetaTable)

判斷資料表中繼資料是否可供使用。Determines whether table metadata is available.

EnableDynamicData(INamingContainer, Type)

針對指定的資料控制項啟用動態資料行為。Enables Dynamic Data behavior for the specified data control.

EnableDynamicData(INamingContainer, Type, IDictionary<String,Object>)

針對指定的資料控制項啟用動態資料行為。Enables Dynamic Data behavior for the specified data control.

EnableDynamicData(INamingContainer, Type, Object)

針對指定的資料控制項啟用動態資料行為。Enables Dynamic Data behavior for the specified data control.

適用於

另請參閱