Freigeben über


Control.CreateChildControls-Methode

Wird vom ASP.NET-Seitenframework aufgerufen, um Serversteuerelemente mit kompositionsbasierter Implementierung zu benachrichtigen, dass alle enthaltenen untergeordneten Steuerelemente als Vorbereitung auf einen Postback oder eine Wiedergabe erstellt werden sollen.

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

Syntax

'Declaration
Protected Friend Overridable Sub CreateChildControls
'Usage

Me.CreateChildControls
protected internal virtual void CreateChildControls ()
protected public:
virtual void CreateChildControls ()
protected void CreateChildControls ()
protected internal function CreateChildControls ()

Hinweise

Wenn Sie ein zusammengesetztes oder aus Vorlagen gebildetes Serversteuerelement entwickeln, müssen Sie diese Methode überschreiben. Steuerelemente, die die CreateChildControls-Methode überschreiben, sollten die INamingContainer-Schnittstelle implementieren, um Namenskonflikte zu vermeiden.

Weitere Informationen finden Sie unter Vorlagen für ASP.NET-Webserver-Steuerelemente und unter Entwickeln von benutzerdefinierten ASP.NET-Serversteuerelementen.

Beispiel

Im folgenden Beispiel wird eine überschriebene Version der CreateChildControls-Methode veranschaulicht. In dieser Implementierung zeigt das zusammengesetzte Steuerelement ein TextBox-Steuerelement an, das in zwei Literalsteuerelemente mit HTML-Darstellung eingeschlossen ist.

' Override CreateChildControls to create the control tree.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="Execution")> _
Protected Overrides Sub CreateChildControls()
   
   ' Add a LiteralControl to the current ControlCollection.
   Me.Controls.Add(New LiteralControl("<h3>Value: "))
   
   
   ' Create a text box control, set the default Text property, 
   ' and add it to the ControlCollection.
   Dim box As New TextBox()
   box.Text = "0"
   Me.Controls.Add(box)
   
   Me.Controls.Add(New LiteralControl("</h3>"))
End Sub 'CreateChildControls
// Override CreateChildControls to create the control tree.
 [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="Execution")]
 protected override void CreateChildControls() {

     // Add a LiteralControl to the current ControlCollection.
     this.Controls.Add(new LiteralControl("<h3>Value: "));


     // Create a text box control, set the default Text property, 
     // and add it to the ControlCollection.
     TextBox box = new TextBox();
     box.Text = "0";
     this.Controls.Add(box);

     this.Controls.Add(new LiteralControl("</h3>"));
 }
// Override CreateChildControls to create the control tree.
/** @attribute System.Security.Permissions.PermissionSet(
    System.Security.Permissions.SecurityAction.Demand, Name = "Execution")
 */
protected void CreateChildControls()
{
    // Add a LiteralControl to the current ControlCollection.
    this.get_Controls().Add(new LiteralControl("<h3>Value: "));
    // Create a text box control, set the default Text property, 
    // and add it to the ControlCollection.
    TextBox box = new TextBox();
    box.set_Text("0");
    this.get_Controls().Add(box);

    this.get_Controls().Add(new LiteralControl("</h3>"));
} //CreateChildControls
// Override CreateChildControls to create the control tree.
 protected override function CreateChildControls() 
 {

     // Add a LiteralControl to the current ControlCollection.
     this.Controls.Add(new LiteralControl("<h3>Value: "));

     // Create a text box control, set the default Text property, 
     // and add it to the ControlCollection.
     var box : TextBox = new TextBox();
     box.Text = "0";
     this.Controls.Add(box);

     this.Controls.Add(new LiteralControl("</h3>"));
 }

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
Controls
ControlCollection
ChildControlsCreated
INamingContainer

Weitere Ressourcen

Entwickeln von benutzerdefinierten ASP.NET-Serversteuerelementen
Vorlagen für ASP.NET-Webserver-Steuerelemente