Replace the default widget view through widget definitions

To customize the default view of a widget type, you actually need to replace the existing widget template with a new one that you create. The new template is a modified version of the existing widget template.

PREREQUISITES:
  • You have downloaded the WidgetsTemplates.zip file from the Sitefinity CMS GitHub repository.
  • You have unzipped the WidgetsTemplates.zip file and copied the TitlesDatesSummariesListView.ascx file.

Modify the default widget

You now need to replace the default widget view with a custom one:

  1. Open Visual Studio and in the context menu of your project, click Add » New Item... » Web User Control.
    Name the new web user control RaplaceDefaultWidget.ascx
  2. Paste the contents of the TitlesDatesSummariesListView.ascx file located in the Sitefinity CMS SDK installation folder.
  3. To extend the template functionality and add dropdown menu, add a RadComboBox.

Use the following markup:

Implement the code behind

Once you create the custom template, you need to implement the code-behind.
Perform the following:

  1. Create a class and name it RaplaceDefaultWidget.cs
  2. Make the class inherit from the default Telerik.Sitefinity.Modules.News.Web.UI.MasterListView class.
  3. In the new class, override the LayoutTemplatePath property of the MasterListView class and point it to the custom template you created.
  4. Add a reference to the RadComboBox controls so you can operate with them.      
  5. Override the InitializeControls method of the MasterListView class and implement our business logic for populating the filter options.
  6. Once you set the DataSource, bind it to the RadComboBox control.
  7. Override the GetItemsList() method - this is where Sitefinity CMS constructs the query and gets the associated items. Get the selected value from the categories RadComboBox and apply this value via the SelectVallue property to the filter expression.
  8. Override the OnPreRender() method.

Use the following code sample:

You now need to For developers: Map the FilterContentViewFrontend template to the News widget with all News widget instances.

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?