Provides a collection container that enables ASP.NET server controls to maintain a list of their child controls.
Assembly: System.Web (in System.Web.dll)
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ Public Class ControlCollection _ Implements ICollection, IEnumerable
Dim instance As ControlCollection
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class ControlCollection : ICollection, IEnumerable
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)] [AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)] public ref class ControlCollection : ICollection, IEnumerable
public class ControlCollection implements ICollection, IEnumerable
You can access any of the properties and methods of the ControlCollection class through the Control.Controls property. Since the Control class is the base class for all ASP.NET server controls, all server controls inherit this property.
For more information about collections, see Collections and Data Structures.
The following code example overrides the Control.CreateChildControls method to create two controls, both instances of the custom class named ChildControl, which has a string property named Message. When created, the two controls are added to the ControlCollection. The Add method is called on each of these controls to add them to the class that contains this version of Control.CreateChildControls. The ChildControlsCreated property is set to true so that these controls will not be created again unnecessarily.
Protected Overrides Sub CreateChildControls() ' Creates a new ControlCollection. Me.CreateControlCollection() ' Create child controls. Dim firstControl As New ChildControl() firstControl.Message = "FirstChildControl" Dim secondControl As New ChildControl() secondControl.Message = "SecondChildControl" Controls.Add(firstControl) Controls.Add(secondControl) ' Prevent child controls from being created again. ChildControlsCreated = True End Sub 'CreateChildControls
protected override void CreateChildControls() { // Creates a new ControlCollection. this.CreateControlCollection(); // Create child controls. ChildControl firstControl = new ChildControl(); firstControl.Message = "FirstChildControl"; ChildControl secondControl = new ChildControl(); secondControl.Message = "SecondChildControl"; Controls.Add(firstControl); Controls.Add(secondControl); // Prevent child controls from being created again. ChildControlsCreated = true; }
-
AspNetHostingPermission
for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
-
AspNetHostingPermission
for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System.Web.UI.ControlCollection
System.Web.UI.EmptyControlCollection
System.Web.UI.HtmlControls.HtmlTable.HtmlTableRowControlCollection
System.Web.UI.HtmlControls.HtmlTableRow.HtmlTableCellControlCollection
System.Web.UI.WebControls.Table.RowControlCollection
System.Web.UI.WebControls.TableRow.CellControlCollection
System.Web.UI.WebControls.ViewCollection
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.