User and Custom widgets
Sitefinity CMS comes with a set of built-in widgets, which can be directly used in the pages you create. Such widgets are the News, Image gallery, and Video gallery. Widgets allow you to display the content you create and configure how you want your content displayed.
Apart from Sitefinity’s built-in widgets, you can also create your own widgets and use them side by side with the default ones. That is, implement new widget to specifically serve your business case needs and functionality requirements by implementing your own custom logic.
You can create a new:
- Custom widget
A compiled ASP.NET Web Server Control
- User widget
A standard ASP.NET User Control
|User widget |
|Custom widget |
|Ease of creation |
|Easier to build, Visual Designer support |
|Takes more time and experience to build |
|Deployment ||Not meant to be deployed in multisite environment |
|Easier to deploy: consists of a single assembly |
|Interchangeable templates |
|No ||Yes |
|Widget designer |
|No || |
For more details about the different types of widgets, see Overview: Types of widgets.
When implementing a new widget, the general steps you follow are:
- Create a new empty widget in your project in Visual Studio.
- Implement the widget’s markup and functionality.
- Register the new widget in the widget toolbox in Sitefinity's backend.
Depending on the type of new widget you create, the new widget you create in Visual Studio and the registration process are different. In addition, implementing the markup and the logic of the new widget are specific for each widget.
NOTE: When you develop widgets for Sitefinity CMS, the system imposes no special requirements. You can use widgets created for other systems by including them in the Sitefinity CMS toolbox.
Subscribing to events
To subscribe to:
- Server events - use only the .cs file
- Client events - use only the .js file
The reason is when you subscribe to events, the lifecycle of the Sitefinity CMS application is modified. Therefore, if you attempt to subscribe to an event through the .ascx file, the event will not fire.
Data dependent and data independent widgets
To access the data in the application, your new widget must also be able to communicate with the existing modules in the Sitefinity CMS application. This is achieved by using either the Fluent API or the Native API.
Your widget can also be data independent. An analog clock widget, which displays the current time, is an example of such widget.
For more information, see:
Widget designer and property editor
By default, each widget in Sitefinity CMS toolbox has a property editor, which allows the widget to be customized. It includes all of the public properties that are exposed by the widget. You can also replace the property editor with a widget designer. For more information about the widget designers, see Overview: Widget designers.
Register the new widget
To use a widget that is not part of the Sitefinity CMS toolbox, you must register it. To register a widget, you need to:
- Reference the widget in the Sitefinity CMS application.
NOTE: This step does not apply for user widgets, because they are always part of the application project.
- Add the widget to Sitefinity CMS toolbox in one of the following ways:
- Register the widget via Sitefinity’s backend.
- Add the widget to the ToolboxesConfig.config file.
You can also refer to a number of tutorials in Tutorials: Create widgets.