Freigeben über


Control.CreateControlCollection-Methode

Erstellt ein neues ControlCollection-Objekt, das die untergeordneten Steuerelemente (literale und Serversteuerelemente) des Serversteuerelements aufnehmen soll.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

Syntax

'Declaration
Protected Overridable Function CreateControlCollection As ControlCollection
'Usage
Dim returnValue As ControlCollection

returnValue = Me.CreateControlCollection
protected virtual ControlCollection CreateControlCollection ()
protected:
virtual ControlCollection^ CreateControlCollection ()
protected ControlCollection CreateControlCollection ()
protected function CreateControlCollection () : ControlCollection

Rückgabewert

Ein ControlCollection-Objekt, das die untergeordneten Serversteuerelemente des aktuellen Serversteuerelements enthält.

Hinweise

Überschreiben Sie diese Methode in einem benutzerdefinierten Serversteuerelement, wenn Sie ein Auflistungsobjekt erstellt haben, das von der ControlCollection-Klasse abgeleitet ist. Sie können anschließend diese Auflistungsklasse im Überschreibungsvorgang dieser Methode instanziieren.

Beispiel

Im folgenden Beispiel wird die CreateControlCollection-Methode überschrieben, um eine Instanz einer CustomControlCollection-Klasse zu erstellen, die von der ControlCollection-Klasse erbt.

' Override the CreateControlCollection method to 
' write to the Trace object when tracing is enabled
' for the page or application in which this control
' is included.   
Protected Overrides Function CreateControlCollection() As ControlCollection
    Return New CustomControlCollection(Me)
End Function
// Override the CreateControlCollection method to 
// write to the Trace object when tracing is enabled
// for the page or application in which this control
// is included.   
protected override ControlCollection CreateControlCollection()
{
    return new CustomControlCollection(this);
}

Im folgenden Codebeispiel wird die CreateControlCollection-Methode in einer Überladung eines benutzerdefinierten Serversteuerelements der CreateChildControls-Methode verwendet. Die neue Auflistung wird erstellt und dann mit den beiden untergeordneten Steuerelementen firstControl und secondControl aufgefüllt.

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

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

Control-Klasse
Control-Member
System.Web.UI-Namespace
ControlCollection