Build a page widget: Implement the page widget class

You can use the following procedure as a guideline for building a custom widget.

First, you create a class and inherit from the SimpleView class. There are some abstract methods and properties you have to override.
Then, you can add the public properties that will show up in the dialog. In this tutorial, it is the Message property. Then, you can add control references for the controls added in the template.

InitializeControls method

As with all Sitefinity CMS widgets that inherit from SimpleView, you must override the InitializeControls method. You can think of this as an alternative of the CreateChildControls method in custom ASP.NET controls. You can implement your control’s logic here.

In this case you are getting the value from the Message property and set it to the MessageLabel, if it is not null. Otherwise, set the label text to "Hello, World!".

LayoutTemplateName property

This is not specific to field controls, but all widgets that inherit from SimpleView. Note that this property is obsolete. You can use the LayoutTemplatePath instead. You can return null or String.Empty in your project.

LayoutTemplatePath property

Although it is not abstract, we recommend that you override the LayoutTemplatePath property. Similar to all widgets in Sitefinity CMS, you should return a path to the template used by your widget. 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?