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:
- Create a new custom control in Visual Studio.
The custom control holds the logic of the new widget.
- Inherit the SimpleView or SimpleScriptView class.
- Create a template.
- Reference the template.
- Reference the new custom widget.
- (Optional) To implement client-side functionality, override the GetScriptDescriptors method and register the markup controls on the client-side.
- Register the widget in Sitefinity CMS toolbox.