Build a custom field control: Implement the field control class

To build a custom field control, perform the following:

  1. Open your project in Visual Studio.
  2. Under SitefinityWebApp, create a folder and name it FieldControls
  3. Inside the folder, create a class and name it MyCustomFieldControl.cs
  4. Inherit from the FieldControl class.
  5. Override the InitializeControls method.
    As with all Sitefinity CMS widgets that inherit from SimpleView, you must override the InitializeControls method. You can implement your control’s logic at this step.
  6. Override the TitleControl property.
    This property returns a control from the template of your field control, which will display the title. All field controls have a title, displayed in the backend form when in Write mode. You can use the Container.GetControl() generic method that is available in all Sitefinity CMS widgets inheriting from SimpleView, and provide the ID. You can have a different title control in Read and Write mode.
  7. Override the DescriptionControl property.
    This property returns a control from the template, which will display the description of your custom field control. As with the TitleControl, you can have a different description in Read and Write mode.
  8. Override the ExampleControl property.
    This property returns a control from the template, which will display an example of the value that your field control expects from the user.
  9. Override the LayoutTemplatePath property.
    You must return a path to the template used by your field control. You can either use a path to an embedded resource (recommended), or an external file. For more information, see VirtualPathProvider.

Use the following code sample:

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?