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.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. 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?