Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TemplateBasedControl.TemplateContainer Property

Gets the container control that instantiates the content template.

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
public virtual TemplateContainer TemplateContainer { get; }

Property Value

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

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.
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.