Wednesday, December 13, 2006

How to implement CreateControlHierarcy in a Composite Control

There is a good article about how to implement a composite control and itexplains the usage of this method in detail.
http://msdn2.microsoft.com/en-us/library/aa479016.aspx

CreateChildControls must accomplish at least the following tasks:
-Clear the Controls collection,
-Build the control's tree
-Clear the viewstate of child controls.

protected override void CreateChildControls()
{
Controls.Clear();
//If it is not in design mode, get the posts and display them
if ((Page.Site == null) (!Page.Site.DesignMode))
{
CreateControlHierarchy(posts);
}
else //Set design time properties
{
this.Width = 100;
this.Height = 10;
}
ClearChildViewState();
}

No comments: