Control.CreateControlCollection Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Létrehoz egy új ControlCollection objektumot a kiszolgálóvezérlő gyermekvezérlőinek (konstans és kiszolgáló) tárolásához.
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
Válaszok
Az ControlCollection aktuális kiszolgálóvezérlő gyermekkiszolgáló-vezérlőinek tárolására szolgáló objektum.
Példák
Az alábbi példakód felülírja az CreateControlCollection osztály egy példányának CustomControlCollection létrehozására szolgáló metódust, amely az ControlCollection osztálytól öröklődik.
// 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
Az alábbi példakód a CreateControlCollection metódus egyéni kiszolgálóvezérlő-felülbírálásában használja a metódust CreateChildControls . Az új gyűjtemény létrejön, majd két gyermekvezérlővel firstControl és secondControl.
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
Megjegyzések
Felülbírálhatja ezt a metódust egy egyéni kiszolgálóvezérlőben, ha létrehozott egy gyűjteményobjektumot, amely az ControlCollection osztályból származik. Ezt követően a metódus felülbírálásával példányosíthatja a gyűjteményosztályt.