TemplateBasedControl.CreateChildControls 方法
创建子TemplateBasedControl类的控件。
命名空间: Microsoft.SharePoint.WebControls
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Protected Overrides Sub CreateChildControls
用法
Me.CreateChildControls()
protected override void CreateChildControls()
备注
根据TemplateOverride属性中指定的值, CreateChildControls方法实例的Template属性或AlternateTemplate属性中。或者,它允许ControlTemplate属性确定的呈现模板实例化的逻辑。
如果TemplateOverride属性, NoneControlTemplate属性的逻辑确定使用哪些模板。如果TemplateOverride属性重写, Both中实例化Template属性,除非它的值为空引用(无 在 Visual Basic 中),可种情况下AlternateTemplate属性。
示例
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.
}
Protected Overrides Sub CreateChildControls()
If Me.Field IsNot Nothing OrElse 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 an non-null underlying ISBNField or control mode is Display
' Do nothing if the ISBNField is null or control mode is Display.
End Sub
另请参阅
引用
Microsoft.SharePoint.WebControls 命名空间