ParseChildrenAttribute Constructor (Boolean)
Collapse the table of content
Expand the table of content

ParseChildrenAttribute Constructor (Boolean)

Initializes a new instance of the ParseChildrenAttribute class using the ChildrenAsProperties property to determine if the elements that are contained within a server control are parsed as properties of the server control.

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

public ParseChildrenAttribute(
	bool childrenAsProperties


Type: System.Boolean
true to parse the elements as properties of the server control; otherwise, false.

If childrenAsProperties is false, the elements that are contained within the server control are parsed as a control. false is the default for ParseChildrenAttribute.

The code example in this section contains two parts. The first code example demonstrates how to set properties for the ParseChildrenAttribute class. The second code example demonstrates how to use classes in an ASP.NET page.

The following code example demonstrates how to set the ParseChildrenAttribute object for a custom server control named CollectionPropertyControl. When the ParseChildrenAttribute is declared before the class defining CollectionPropertyControl, the ParseChildrenAttribute sets the ChildrenAsProperties property to true.

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

namespace Samples.AspNet.CS.Controls
   // Create a class that will be rendered as a child of the control
   // that has the ParseChildren attribute applied to it.
   public sealed class Employee
      private String name;
      private String title;
      private String alias;

      public Employee():this ("","",""){}

      public Employee (String name, String title, String alias)
      { = name;
         this.title = title;
         this.alias = alias;
      public String Name
            return name;
            name = value;

      public String Title
            return title;
            title = value;

      public String Alias
            return alias;
            alias = value;
   // Use this Boolean version of the ParseChildrenAttribute constructor
   // to set the ChildrenAsProperties property to true. Any properties of the
   // the CollectionPropertyControl custom control will be used as parsable
   // children.
   public sealed class CollectionPropertyControl : Control
      private String header;
      private ArrayList employees = new ArrayList();

      public String Header
            return header;
            header = value;

      public ArrayList Employees
            return employees;

      // Override the CreateChildControls method to 
      // add child controls to the Employees property when this
      // custom control is requested from a page.
      protected override void CreateChildControls()
         Label label = new Label();
         label.Text = Header;
         label.BackColor = System.Drawing.Color.Beige;
         label.ForeColor = System.Drawing.Color.Red;
         Controls.Add(new LiteralControl("<BR> <BR>"));

         Table table = new Table();
         TableRow htr = new TableRow();

         TableHeaderCell hcell1 = new TableHeaderCell();    
         hcell1.Text = "Name";

         TableHeaderCell hcell2 = new TableHeaderCell();
         hcell2.Text = "Title";

         TableHeaderCell hcell3 = new TableHeaderCell();
         hcell3.Text = "Alias";

         table.BorderWidth = 2;
         table.BackColor = System.Drawing.Color.Beige;
         table.ForeColor = System.Drawing.Color.Red;
         foreach (Employee employee in Employees)
            TableRow tr = new TableRow();

            TableCell cell1 = new TableCell();
            cell1.Text = employee.Name;

            TableCell cell2 = new TableCell();
            cell2.Text = employee.Title;

            TableCell cell3 = new TableCell();
            cell3.Text = employee.Alias;



The following code example demonstrates how to use the CollectionPropertyControl and Employee classes in an ASP.NET page. One instance of the Employee class is added declaratively and another is added programmatically.

<%@ Page Language="C#" %>
<%@ Register TagPrefix="AspSample" Assembly="Samples.AspNet.CS.Controls" Namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

  protected void Page_Load(object sender, EventArgs e)
    // Create a new employee object and add it to the custom control.
    Employee e1 = new Employee("Employee 2", "Title 2", "Alias 2");

    // Verify attribute values.
    ParseChildrenAttribute p = 

    StringBuilder sb = new StringBuilder();
    sb.Append("The ChildControlType property is " + p.ChildControlType.ToString() + "<br />");
    sb.Append("The ChildrenAsProperties property is " + p.ChildrenAsProperties.ToString() + "<br />");
    sb.Append("The IsDefaultAttribute method returns " + p.IsDefaultAttribute().ToString());
    Message.Text = sb.ToString();


<html xmlns="" >
<head runat="server">
    <title>ParseChildrenAttribute Example</title>
    <form id="form1" runat="server">
      <asp:Label ID="Message"
      <AspSample:CollectionPropertyControl id="CollectionPropertyControl1" 
        <AspSample:Employee Name="Employee 1" 
                            Title="Title 1" 
                            Alias="Alias 1" />

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2016 Microsoft