TemplateBasedControl.TemplateContainer 属性

获取实例化内容的模板的容器控件。

命名空间:  Microsoft.SharePoint.WebControls
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public Overridable ReadOnly Property TemplateContainer As TemplateContainer
    Get
用法
Dim instance As TemplateBasedControl
Dim value As TemplateContainer

value = instance.TemplateContainer
public virtual TemplateContainer TemplateContainer { get; }

属性值

类型:Microsoft.SharePoint.WebControls.TemplateContainer
实例化内容模板TemplateContainer对象。

示例

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.
}
Protected Overrides Sub CreateChildControls()
    If Me.Field IsNot Nothing AndAlso Me.ControlMode <> SPControlMode.Display Then
        ' Make sure inherited child controls are completely rendered.
        MyBase.CreateChildControls()

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

        If Not Me.Page.IsPostBack Then
            If Me.ControlMode = SPControlMode.New Then
                textBox.Text = "0-000-00000-0"

            End If ' end assign default value in New mode

        End If ' end if this is not a postback

     'Do not reinitialize on a postback.

    End If ' 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.
End Sub

另请参阅

引用

TemplateBasedControl 类

TemplateBasedControl 成员

Microsoft.SharePoint.WebControls 命名空间

其他资源

Patterns of Custom Field Rendering

Custom Field Types

Walkthrough: Creating a Custom Field Type