Control.CreateControlCollection Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Crea un nuovo ControlCollection oggetto per contenere i controlli figlio (sia letterali che server) del controllo server.
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
Valori restituiti
Oggetto ControlCollection che contiene i controlli server figlio del controllo server corrente.
Esempio
Nell'esempio di codice seguente viene eseguito l'override del CreateControlCollection metodo per creare un'istanza di una CustomControlCollection classe , che eredita dalla ControlCollection classe .
// 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
Nell'esempio di codice seguente viene utilizzato il CreateControlCollection metodo in un override personalizzato del controllo server del CreateChildControls metodo . La nuova raccolta viene creata e quindi popolata con due controlli figlio e 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
Commenti
Eseguire l'override di questo metodo in un controllo server personalizzato se è stato creato un oggetto raccolta derivato dalla ControlCollection classe . È quindi possibile creare un'istanza di tale classe di raccolta nell'override di questo metodo.