Create a new custom widget

In Sitefinity CMS, you can create your new custom widgets as standard ASP.NET custom controls or you can derive them from one of the built-in base classes – SimpleView and SimpleScriptView. They are designed to improve the development of controls for Sitefinity CMS.

In addition to the LayoutTemplateName, the SimpleView class exposes the LayoutTemplatePath property. It is used to refer an external template that is placed outside of the assembly. If you do not set LayoutTemplatePath property, Sitefinity CMS enables you to use your own templates instead of the embedded template. With this feature of custom widgets, you can adjust the looks of the widget with minimal amount of work.

The SimpleView class attempts to load the template located at LayoutTemplatePath value, but falls back to the LayoutTemplateName value, if there is no path provided, or the template could not be found. This provides customization while, at the same time, preserves stability in case the user input was wrong.

When creating new custom widgets, to map the markup file with the code-behind for a new custom widget, you must override the LayoutTemplatePath property and put the path of the markup there. When registering the new widget in Sitefinity CMS toolbox, you must provide the whole path, as opposed to only the virtual path.

Keep in mind that you cannot subscribe to events through the .ascx file of the widget. For more information, see Overview: User and Custom widgets.

The new custom widget can reside in Sitefinity CMS solution or in another solution.

If you want to enhance your control to have a smoother UI, represented for example, by a Kendo application. You can derive your custom widget from the KendoView class.

For more information, about Kendo, see Kendo UI documentation.

To create a new custom widget, you follow these steps:

  1. Create a new custom control in Visual Studio.

    The custom control holds the logic of the new widget.

  2. Inherit the SimpleView or SimpleScriptView class.
  3. Create a template.
  4. Reference the template.
  5. Reference the new custom widget.
  6. (Optional) To implement client-side functionality, override the GetScriptDescriptors method and register the markup controls on the client-side.
  7. Register the widget in Sitefinity CMS toolbox.

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?