This topic has not yet been rated - Rate this topic

TemplateBasedControl.CreateChildControls Method

Creates the child controls of the TemplateBasedControl class.

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
protected override void CreateChildControls()

Depending on the value specified in the TemplateOverride property, the CreateChildControls method instantiates either the Template property or the AlternateTemplate property; or, it lets the logic of the ControlTemplate property determine which rendering template to instantiate.

If the TemplateOverride property is None, the logic of the ControlTemplate property determines which template is used. If the TemplateOverride property override is Both, the Template property is instantiated, unless it's value is null, in which case the AlternateTemplate property is used.

The following example shows an override of this method in a custom field rendering control. See Walkthrough: Creating a Custom Field Type for the full example.

protected override void CreateChildControls()
{
    if (this.Field != null || this.ControlMode == SPControlMode.Display)
    {
        // Make sure inherited child controls are completely rendered.
        base.CreateChildControls();

        // Associate child controls in the .ascx file with the 
        // fields allocated by this control.
        this.ISBNPrefix = (Label)TemplateContainer.FindControl("ISBNPrefix");
        this.textBox = (TextBox)TemplateContainer.FindControl("TextField");

        if (!this.Page.IsPostBack)
        {
            if (this.ControlMode == SPControlMode.New)
            {
                textBox.Text = "0-000-00000-0";

            } // end assign default value in New mode

        }// end if this is not a postback 

     //Do not reinitialize on a postback.

    }// end if there is an non-null underlying ISBNField or control mode is Display

 // Do nothing if the ISBNField is null or control mode is Display.
}
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ