Export (0) Print
Expand All
Expand Minimize
1 out of 2 rated this helpful - Rate this topic

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.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)
public interface INamingContainer

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, 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. For more information, see ASP.NET Control Designers Overview.

TopicLocation
How to: Create Templated ASP.NET User ControlsBuilding ASP .NET Web Applications
How to: Create Templated ASP.NET User ControlsBuilding ASP .NET Web Applications

The following code 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.

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;
            }
        }
    }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft. All rights reserved.