This documentation is archived and is not being maintained.

ControlCollection Constructor

Initializes a new instance of the ControlCollection class for the parent server control specified in the owner parameter.

[Visual Basic]
Public Sub New( _
   ByVal owner As Control _
public ControlCollection(
   Control owner
public: ControlCollection(
   Control* owner
public function ControlCollection(
   owner : Control


The ASP.NET server control that the control collection is created for.


Exception Type Condition
ArgumentException Occurs if the owner parameter is a null reference (Nothing in Visual Basic).


[Visual Basic] The following code example is a custom ControlCollection class that overrides the constructor to write messages, that includes the name of the Owner property, to the trace log when an instance of the collection is created. You must enable tracing for the page or application for this example to work.

[Visual Basic] 
' Create a custom ControlCollection that writes
' information to the Trace log when an instance
' of the collection is created.
Public Class CustomControlCollection
   Inherits ControlCollection
   Private context As HttpContext

   Public Sub New(ByVal owner As Control)
      context.Trace.Write("The control collection is created.")        
      ' The displays the Name of the control
      ' that uses this collection when tracing is enabled.
      context.Trace.Write("The owner is: " _
       & Me.Owner.ToString())
   End Sub
End Class

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

ControlCollection Class | ControlCollection Members | System.Web.UI Namespace | Controls | Control