Control.ChildControlsCreated Property

Gets a value that indicates whether the server control's child controls have been created.

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

protected bool ChildControlsCreated { get; set; }
/** @property */
protected boolean get_ChildControlsCreated ()

/** @property */
protected void set_ChildControlsCreated (boolean value)

protected function get ChildControlsCreated () : boolean

protected function set ChildControlsCreated (value : boolean)

Not applicable.

Property Value

true if child controls have been created; otherwise, false.

The following example demonstrates an override of the OnDataBinding method of a custom Repeater control. To ensure that child controls are not created until data binding occurs again, the ChildControlsCreated property is set to true after the RepeaterItem objects are created and added to the control's ControlCollection object.

using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TemplateControlSamples
    public class CustomRepeater : Repeater

        // Override to prevent LiteralControls from being added as children.
        protected override void AddParsedSubObject(object o)

        // Override to create repeated items.
        protected override void CreateChildControls()
            object o = ViewState["NumItems"];
            if (o != null)
                // Clear any existing child controls.

                int numItems = (int)o;
                for (int i = 0; i < numItems; i++)
                    // Create an item.
                    RepeaterItem item = new RepeaterItem(i, ListItemType.Item);
                    // Initialize the item from the template.
                    // Add the item to the ControlCollection.

        // Override to create the repeated items from the DataSource.
        protected override void OnDataBinding(EventArgs e)
            if (DataSource != null)
                // Iterate over an ICollection DataSource, creating a new item for each data item.
                IEnumerator dataEnum = ((ICollection)base.DataSource).GetEnumerator();
                int i = 0;
                while (dataEnum.MoveNext())
                    // Create an item.
                    RepeaterItem item = new RepeaterItem(i, ListItemType.Item);
                    item.DataItem = dataEnum.Current;
                    // Initialize the item from the template.
                    // Add the item to the ControlCollection.


                // Prevent child controls from being created again.
                ChildControlsCreated = true;
                // Store the number of items created in view state for postback scenarios.
                ViewState["NumItems"] = i;

The following example demonstrates how to use the custom repeater control in a Web page.

<%@ Page Language="C#" %>
<%@ Register TagPrefix="Samples" Namespace="TemplateControlSamples" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
        ArrayList a = new ArrayList();
        a.Add("data item 1");
        a.Add("data item 2");
        Repeater1.DataSource = a;


<html xmlns="" >
<head runat="server">
    <title>ChildControlsCreated Example</title>
    <form id="form1" runat="server">
        <Samples:CustomRepeater ID="Repeater1" runat="server">
        <ItemTemplate><%# Container.DataItem %> <br /></ItemTemplate>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0