Control.CreateChildControls Method
Assembly: System.Web (in system.web.dll)
When you develop a composite or templated server control, you must override this method. Controls that override the CreateChildControls method should implement the INamingContainer interface to avoid naming conflicts.
For more information, see ASP.NET Web Server Controls Templates and Developing Custom ASP.NET Server Controls.
The following example demonstrates an overridden version of the CreateChildControls method. In this implementation, the composite control displays a TextBox control enclosed in two literal controls that render HTML.
// 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>")); }
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
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
You can buy me a beer later.
Now, if you are using some specialized means of binding data (e.g., Custom Combo Box), load your control tree with "CreateCustomChildControls()", but load your data using "CreateChildControls()".
- 11/19/2010
- Roy S. Oliver