Field controls

A special kind of controls used in Sitefinity CMS are the Field Controls. This article describes what they are, what they can do, how they are typically used, which ones are built-in and how to create your own Field Controls.

What are fields?

A field is a property of any content item in Sitefinity CMS. The built-in modules and content types have fields. When you create dynamic modules and dynamic types, you can also create fields for them. . Examples of fields are:

  • All items of type News Item have a field called Title.
  • All items of type Event have a field called StartDate.

What are field controls?

Field controls are tasked to provide a user interface that can read and write the value of a field.

Where are field controls used?

Field controls can be used:

  • When reading the value of a field, field controls display that value in widget templates.
  • When writing the value of a field, field controls are used in the backend forms (when creating and editing items).

What are the benefits of using field controls?

The notion of field controls invites the question of why you could not just use standard ASP.NET controls and HTML tags for these needs. Can’t we use a normal dropdown to select the value of a field or a normal textbox? The answer is – you can. However, there are advantages to field controls that are not available from other controls:

  • Easily switch between different views of a content item
    When you’re building user interface for editing and showing an item, often you need to provide several views for the same item – edit, preview, insert. Those usually contain all item fields in some form. With field controls, you can build all views of an item by using the same controls, and just switching from edit to preview mode.
  • Ability to define structured user interfaces
    Field controls let you build user interfaces declaratively. Instead of implementing a separate control for each scenario and form, you can define what forms you want and what field controls should be there in each form. This is possible due to the concept of definitions, which needs its own documentation section.
  • Built-in ready-to-use UI for complex property types
    Instead of reinventing the wheel, you can reuse user interface components already available in other areas of Sitefinity CMS. It is likely that a similar scenario like the one you are implementing has been done before, and you can just reuse it.
  • Out of the box compatibility with the Sitefinity CMS Look
    We advise that you stick to the Sitefinity CMS look and feel for custom modules that have backend user interface. For the purpose, you need to use the same UI elements and styles. With field controls, you get this out of the box. Your UI will look the same as the UI of the default modules in Sitefinity.

DisplayMode in field controls

The following concepts are important when working with field controls.

You can (and should) provide many views to work with an item in your custom modules. You can have different UI for inserting, editing and viewing an item. To support these different views, field controls have a DisplayMode property, which can be either Read or Write. Read mode is used when you want to display the value of a field (view), Write mode is used when you want to edit the value of a field (insert, edit).

The UI of a field controls is always different in Read and Write mode. The mode is switched automatically by Sitefinity CMS, depending on the context in which the field control is used. Sometimes the UI in the different modes is drastically different, and usually more complex in Write mode.  If we have a field that will associate an item with a category, then it should only display the category’s name in Read mode, maybe as a link. But when in Write mode, the field control should make it possible for the user to select from pre-existing categories or create new ones to associate the item with.

Field controls

Additional resources

ARTICLES

Overview: Custom fields

Add new fields to widget templates

Was this article helpful?