INamingContainer Interface
Identifies a container control that creates a new ID namespace within a Page object's control hierarchy. This is a marker interface only.
[Visual Basic] Public Interface INamingContainer [C#] public interface INamingContainer [C++] public __gc __interface INamingContainer [JScript] public interface INamingContainer
Classes that Implement INamingContainer
| Class | Description |
|---|---|
| CheckBoxList | Creates a multi selection check box group that can be dynamically created by binding the control to a data source. |
| DataGrid | A data bound list control that displays the items from data source in a table. The DataGrid control allows you to select, sort, and edit these items. |
| DataGridItem | Represents an item (row) in a DataGrid control. |
| DataList | A data bound list control that displays items using templates. |
| DataListItem | Represents an item in a DataList control. |
| RadioButtonList | Represents a list control that encapsulates a group of radio button controls. |
| Repeater | A data-bound list control that allows custom layout by repeating a specified template for each item displayed in the list. |
| RepeaterItem | Represents an item in the Repeater control. |
| TemplateControl | Provides the Page class and the UserControl class with a base set of functionality. |
Remarks
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. 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. These controls include the Repeater, DataGrid, DataList, ListBox, CheckBoxList, HtmlSelect, and RadioButtonList controls.
When you develop templated controls, you should implement this interface to avoid naming conflicts on a page. For more information, see Developing a Composite Control.
Example
The following example demonstrates a templated custom server control that implements the INamingContainer interface. When this custom server control is used in an .aspx file, it will provide a unique namespace for any server controls that it contains.
[Visual Basic] Imports System 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 [C#] 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; } } } } [C++] #using <mscorlib.dll> #using <System.Web.dll> #using <System.dll> using namespace System; using namespace System::Collections; using namespace System::Web; using namespace System::Web::UI; public __gc class RepeaterItem : public Control, public INamingContainer { private: int itemIndex; private: Object* dataItem; public: RepeaterItem(int itemIndex, Object* dataItem) { this->itemIndex = itemIndex; this->dataItem = dataItem; } public: __property Object* get_DataItem() { return dataItem; } public: __property int get_ItemIndex() { return itemIndex; } }; [JScript] import System; import System.Collections; import System.Web; import System.Web.UI; package TemplateControlSamples { public class RepeaterItem extends Control implements INamingContainer { private var itemIndex : int; private var dataItem; function RepeaterItem(itemIndex : int, dataItem) { this.itemIndex = itemIndex; this.dataItem = dataItem; } function get DataItem() { return dataItem; } function get ItemIndex() : int { return itemIndex; } } }
Requirements
Namespace: System.Web.UI
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
Assembly: System.Web (in System.Web.dll)
See Also
System.Web.UI Namespace | Control | Page | Developing a Templated Control