TemplateBasedControl.TemplateContainer property

Gets the container control that instantiates the content template.

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

public virtual TemplateContainer TemplateContainer { get; }

Property value

Type: Microsoft.SharePoint.WebControls.TemplateContainer
A TemplateContainer object that instantiates the content template.

Examples

The following example shows how the TemplateContainer property can be used to obtain a reference to a control in a rendering template (defined in an .ascx file). 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 a non-null underlying ISBNField and control mode is not Display

 // Do nothing if the ISBNField is null or control mode is Display.
}

See also

Reference

TemplateBasedControl class

TemplateBasedControl members

Microsoft.SharePoint.WebControls namespace

Other resources

Patterns of Custom Field Rendering

Custom Field Types

Walkthrough: Creating a Custom Field Type