Provides a collection container that enables ASP.NET server controls to maintain a list of their child controls.
System.Web.UIControlCollection
System.Web.UIEmptyControlCollection
System.Web.UI.HtmlControlsHtmlTableHtmlTableRowControlCollection
System.Web.UI.HtmlControlsHtmlTableRowHtmlTableCellControlCollection
System.Web.UI.WebControlsTableRowControlCollection
System.Web.UI.WebControlsTableRowCellControlCollection
System.Web.UI.WebControlsViewCollection
Assembly: System.Web (in System.Web.dll)
Public Class ControlCollection _
Implements [%$TOPIC/kbe31ba9_en-us_VS_110_2_0_0_0_0%], [%$TOPIC/kbe31ba9_en-us_VS_110_2_0_0_0_1%]
public class ControlCollection : [%$TOPIC/kbe31ba9_en-us_VS_110_2_0_1_0_0%],
[%$TOPIC/kbe31ba9_en-us_VS_110_2_0_1_0_1%]
public ref class ControlCollection : [%$TOPIC/kbe31ba9_en-us_VS_110_2_0_2_0_0%],
[%$TOPIC/kbe31ba9_en-us_VS_110_2_0_2_0_1%]
type ControlCollection =
class
interface [%$TOPIC/kbe31ba9_en-us_VS_110_2_0_3_0_0%]
interface [%$TOPIC/kbe31ba9_en-us_VS_110_2_0_3_0_1%]
end
The ControlCollection type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | ControlCollection | Initializes a new instance of the ControlCollection class for the specified parent server control. |
| Name | Description | |
|---|---|---|
![]() | Count | Gets the number of server controls in the ControlCollection object for the specified ASP.NET server control. |
![]() | IsReadOnly | Gets a value indicating whether the ControlCollection object is read-only. |
![]() | IsSynchronized | Gets a value indicating whether the ControlCollection object is synchronized. |
![]() | Item | Gets a reference to the server control at the specified index location in the ControlCollection object. |
![]() | Owner | Gets the ASP.NET server control to which the ControlCollection object belongs. |
![]() | SyncRoot | Gets an object that can be used to synchronize access to the collection of controls. |
| Name | Description | |
|---|---|---|
![]() | Add | Adds the specified Control object to the collection. |
![]() | AddAt | Adds the specified Control object to the collection at the specified index location. |
![]() | Clear | Removes all controls from the current server control's ControlCollection object. |
![]() | Contains | Determines whether the specified server control is in the parent server control's ControlCollection object. |
![]() | CopyTo | Copies the child controls stored in the ControlCollection object to an SystemArray object, beginning at the specified index location in the SystemArray. |
![]() | Equals(Object) | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetEnumerator | Retrieves an enumerator that can iterate through the ControlCollection object. |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | IndexOf | Retrieves the index of a specified Control object in the collection. |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | Remove | Removes the specified server control from the parent server control's ControlCollection object. |
![]() | RemoveAt | Removes a child control, at the specified index location, from the ControlCollection object. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() | AsParallel | Enables parallelization of a query. (Defined by ParallelEnumerable.) |
![]() | AsQueryable | Converts an IEnumerable to an IQueryable. (Defined by Queryable.) |
![]() | CastTResult | Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.) |
![]() | OfTypeTResult | Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.) |
You can access any of the properties and methods of the ControlCollection class through the ControlControls 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 ControlCreateChildControls 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 ControlCreateChildControls. 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;
}
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.
.gif)
.gif)
.gif)
.gif)
.gif)