How to: Create an Editor Control for a Field Type Property
Last modified: September 30, 2009
Applies to: SharePoint Foundation 2010
An editor control for the variable properties of a field type can be used, as an alternative to a PropertySchema Element (Field Types), to render the properties of the field on the New Site Column, Change Site Column, Create Column, and Change Column pages. See Custom Field Type Property Rendering for an overview of the two options and a discussion of when to use each method.
An editor control is defined in an .ascx file in %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\ControlTemplates and in a code-behind file that are compiled into the same assembly as the custom field class. In addition to rendering the properties of the field, the editor control supports column creators who are setting those properties with special functions, such as complicated computational logic, look-up of values from data sources, and custom data validation.
Note We recommend that you name your editor control classes using the following naming convention:
for example, TargetDateFieldEditor or RegularExpressionFieldEditor. In line with this convention, your .ascx file will be named field_type_nameFieldEditor.ascx and will inherit from the code-behind class field_type_nameFieldEditor.
To act as a field editor user control, the code-behind class must do the following:
Inherit from the UserControl class, or a class derived from it.
Implement the IFieldEditor interface.
The IFieldEditor interface includes the following property and methods. Click the name of each to learn more about how to implement it.
DisplayAsNewSection Use this property to specify whether or not you want the control to be displayed in the Additional Column Settings section on the New Site Column, Change Site Column, Create Column, and Change Column pages, or alone in a new section.
OnSaveChange Use this method to validate and save a column-creator's or column-editor's changes to the field (column) properties.
InitializeWithField Use this method to initialize the editor control with either default values or the current property values of the field (column).