Crea un nuovo oggetto ControlCollection per contenere i controlli figlio (letterali e server) del controllo server.
Assembly: System.Web (in System.Web.dll)
Protected Overridable Function CreateControlCollection As ControlCollection
protected virtual ControlCollection CreateControlCollection()
protected: virtual ControlCollection^ CreateControlCollection()
abstract CreateControlCollection : unit -> ControlCollection override CreateControlCollection : unit -> ControlCollection
Valore restituito
Tipo: System.Web.UI.ControlCollectionOggetto ControlCollection che contiene i controlli server figlio del controllo server corrente.
Eseguire l'override di questo metodo in un controllo server personalizzato se è stato creato un oggetto insieme derivato dalla classe ControlCollection. È quindi possibile creare l'istanza di tale classe di insiemi nell'override di questo metodo.
Nell'esempio di codice riportato di seguito viene eseguito l'override del metodo CreateControlCollection per creare un'istanza della classe CustomControlCollection che eredita dalla classe ControlCollection.
' 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); }
Nell'esempio di codice riportato di seguito viene utilizzato il metodo CreateControlCollection di un controllo server personalizzato per sottoporre a override il metodo CreateChildControls. Il nuovo insieme viene creato e poi compilato con due controlli figlio, firstControl e secondControl.
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;
}
.NET Framework
Supportato in: 4, 3.5, 3.0, 2.0, 1.1, 1.0Windows 7, Windows Vista SP1 o versione successiva, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (componenti di base del server non supportati), Windows Server 2008 R2 (componenti di base del server supportati con SP1 o versione successiva), Windows Server 2003 SP2
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.