Control.CreateChildControls Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Appelé par l’infrastructure de page ASP.NET pour notifier les contrôles serveur qui utilisent l’implémentation basée sur la composition pour créer les contrôles enfants qu’ils contiennent en préparation de la publication ou du rendu.
protected:
virtual void CreateChildControls();
protected public:
virtual void CreateChildControls();
protected virtual void CreateChildControls();
protected internal virtual void CreateChildControls();
abstract member CreateChildControls : unit -> unit
override this.CreateChildControls : unit -> unit
Protected Overridable Sub CreateChildControls ()
Protected Friend Overridable Sub CreateChildControls ()
Exemples
L’exemple suivant illustre une version substituée de la CreateChildControls méthode. Dans cette implémentation, le contrôle composite affiche un TextBox contrôle placé entre deux contrôles littéraux qui affichent du code HTML.
Important
Cet exemple contient une zone de texte qui accepte l’entrée utilisateur, qui est une menace de sécurité potentielle. Par défaut, ASP.NET pages web valident que l’entrée utilisateur n’inclut pas de script ou d’éléments HTML. Pour plus d’informations, consultez Vue d’ensemble des exploits de script.
// 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.
<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
Remarques
Lorsque vous développez un contrôle serveur composite ou modèle, vous devez remplacer cette méthode. Les contrôles qui remplacent la CreateChildControls méthode doivent implémenter l’interface INamingContainer pour éviter les conflits de nommage.
Pour plus d’informations, consultez Modèles de contrôles serveurWeb et Developing Custom ASP.NET Server Controls.