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:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?