Control.CreateControlCollection Methode

Definition

Erstellt ein neues ControlCollection Objekt, das die untergeordneten Steuerelemente (literal und server) des Serversteuerelements enthält.

protected:
 virtual System::Web::UI::ControlCollection ^ CreateControlCollection();
protected virtual System.Web.UI.ControlCollection CreateControlCollection();
abstract member CreateControlCollection : unit -> System.Web.UI.ControlCollection
override this.CreateControlCollection : unit -> System.Web.UI.ControlCollection
Protected Overridable Function CreateControlCollection () As ControlCollection

Gibt zurück

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

Beispiele

Im folgenden Codebeispiel 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 override ControlCollection CreateControlCollection()
{
    return new CustomControlCollection(this);
}
' 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

Im folgenden Codebeispiel wird die CreateControlCollection Methode in einer benutzerdefinierten Serversteuerelementüberschreibung der CreateChildControls Methode verwendet. Die neue Auflistung wird erstellt und dann mit zwei untergeordneten Steuerelementen aufgefüllt. firstControlsecondControl


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

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


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 diese Sammlungsklasse dann in der Außerkraftsetzung dieser Methode instanziieren.

Gilt für:

Weitere Informationen