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

注解

实现此接口的任何控件都将创建一个新的命名空间, 在该命名空间中, 所有子控件 ID 属性都保证在整个应用程序中是唯一的。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控件包括、 DataList CheckBoxList 、、ChangePassword、、 、、LoginViewRadioButtonList控件。 Menu SiteMapNodeItem DataGridThese 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.

适用于

另请参阅