다음을 통해 공유


SharePoint Field Controls and Control Templates (ECM)

Applies to: SharePoint Server 2010

In addition to Web Parts, pages in Microsoft SharePoint Server 2010 can contain field controls. Field controls are simple controls that you can create. They use a small amount of code to display the two modes of the controls: one for render time, and one for edit time.

SharePoint Foundation and SharePoint Server 2010 provide several default field controls that you can use in your pages. All field controls that you use in a SharePoint Server 2010 site derive from a base class in SharePoint Foundation named FormComponent. You can extend any of the default SharePoint Foundation and SharePoint Server 2010 controls for your own specific functionality.

You can write a field control of your own by deriving from BaseRichField class, or you can write a field control that derives from the default field controls.

Control templates are a feature that separates data from presentation. Templates define the presentation of the control, and all field controls contained in sites use templates for layout definition.

As a developer, you can do the following:

  • Create and deploy a control template.

  • Deploy a template that overrides a default control template.

  • Edit a template after it is deployed.

Control template definition is similar to field type definition, and it follows the same extensibility and deployment model.

All custom templates are added to the NewTemplates.ascx file. You can define the control template for a custom field control in one of three ways:

  • Set the control template for the control programmatically by using the GetControlTemplate method in the object model.

  • Set the TemplateName attribute or the AlternateTemplateName attribute in the instance of the field control on a page.

  • Instead of defining a template file and referencing it in the control, define the template in the markup of the control itself. This technique is available mostly for Web designers who do not have permissions to install new templates but want to customize the look and feel of a control.

As SharePoint Server 2010 is currently configured, at run time a site uses templates in the following order, depending on how they were defined: markup, TemplateName attribute, then GetControlTemplate method. Template designers can modify this behavior, however, by overriding the GetControlTemplate method. All controls derived from the FormComponent base class can override the GetControlTemplate method to define how a control chooses which template to use. The template logic is then used by all instances of the control.

See Also

Concepts

SharePoint Page Layouts and Master Pages (ECM)

Other Resources

Master Pages