BaseFieldControl.CreateChildControls 方法
创建任何子控件呈现的字段,如 label 控件、 链接控件或文本框控件所需。
命名空间: Microsoft.SharePoint.WebControls
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Protected Overrides Sub CreateChildControls
用法
Me.CreateChildControls()
protected override void CreateChildControls()
备注
CreateChildControls继承自Microsoft ASP.NET 2.0Control类和做到后一种类型的对象的大多数在呈现控件工作。但是, BaseFieldControl和其派生也是模板控件继承TemplateBasedControl: 对于这些控件中的大多数,位于C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\ControlTemplates .ascx 文件中定义的模板执行的许多呈现工作。通常CreateChildControls仅执行"最终波兰"上的控件,如设置子控件的 tab 键索引或指定控件,该样式的 CSS 文件,或者将插入在新建模式下的子控件的默认值。
针对继承者的注释
如果覆盖此方法,您重写,必须调用基方法。
您可能希望来验证用户输入新的或编辑 (列表项) 窗体上的字段的 UI 控件的数据。特别是,如果该字段需要具有一个值,应当实施此要求。( Required属性将记录该字段是否需要)。如果您使用从BaseFieldControl呈现字段的内置Windows SharePoint Services 3.0类之一,然后可以依赖于强制实施Required其内部验证。如果您从BaseFieldControl或其派生之一派生您自己的控件,并且重写CreateChildControls方法,您将需要提供Required以及您想要进行任何其他 UI 级的有效性规则的实施。根据您的字段类型和呈现控件的复杂性,您的用户界面验证逻辑可以Validate方法或CreateChildControls方法或二者的组合。但请记住,则不会调用如果验证逻辑完全在CreateChildControls ,并直接通过对象模型,而不是通过窗体, CreateChildControls域不在调用的 update 和数据有效性。
示例
The following example shows a typical override of CreateChildControls. For the full example, see Walkthrough: Creating a Custom Field Type.
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
另请参阅
引用
Microsoft.SharePoint.WebControls 命名空间
其他资源
Patterns of Custom Field Rendering