How to add additional logic into Sitefinity built in widgets

by
Stanislav Velikov
Jan 23, 2012

It is often needed to extend some of the capabilities of Sitefinity built in widgets. Since the widgets implementation is in Sitefinity assemblies the code files are not directly accessible. To override the methods for the widgets it is needed to inherit from the built in widget and override some of the methods. I will describe two approaches for doing so. One involves inheriting from the widget and creating new control with the modified logic. Another approach is to replace the built in widget with the modified one. The two approaches are interconnected.

First approach:
1.Create a new class in the Sitefinity solution. Then must find out how to inherit one widget. For this example I will be inheriting Sitefinity login control.
2.To find the needed path that should be inherited (Telerik.Sitefinity.Web.UI.PublicControls.LoginControl) go to Administration->Settings->Advanced->Toolboxes->PageControls->Sections->Login->Tools->Login and find textbox: Control CLR Type or Virtual Path. In it you can take the path Telerik.Sitefinity.Web.UI.PublicControls.LoginControl as well as other properties that will not be needed fro this example.
3.In the .class file created in step 1 inherit from Login Control. The class should look like this.

type override keyword to access a list of all methods that can be overridden. Make sure you are calling the base method when overriding to be sure the built in implementation for this method will also be included (base.LoginForm_Authenticate(sender, e);).

Go to Administration->Settings->Advanced->Toolboxes->Toolboxes->PageControls->Sections->Login->Tools and click create new button in the main content area. Register the control withControl CLR Type or Virtual Path: SitefinityWebApp.CustomizedLoginControlName: CustomizedLoginControl

Title: CustomizedLoginControl

The customized control is now available in page edit screen under the Login section and the control is called CustomizedLoginControl.

Note some of the built in widgets that have separate views like news, blogs, events have two views. MasterListView this is the view that displays a list of all news, blogs, events items and sorts them.

Both views are using separate code file so the first approach with registering only one code file as a single control will not be of much use in this case. Refer to the second approach where you will be able to insert logic into a separate view (MasterListView or DetailsView).

Second approach:
With this approach step 1 is the same. To find the proper path to the desired MasterView or DetailsView go to

Administration->Settings->Advanced->ContentView->Controls-> here a big node is expanded that list most of the backend controls. Go to NewsFrontend->Views and here you will see NewsFrontendList and NewsFrontendDetails. This naming is the same for all widgets that have two views (MasterList and Details).
To use different logic for NewsFrontendDetails click the menu item and find the textbox ViewType with content: Telerik.Sitefinity.Modules.News.Web.UI.DetailsSimpleView, this is the path from where the newsDetails code is taken and the path that we need to inherit.

Inherit Telerik.Sitefinity.Modules.News.Web.UI.DetailsSimpleView in the class file created at step one and you will be able to overwrite methods from DetailsView.

To use the new DetailsView register it in the same box ViewType.SitefintiyWebApp.CustomDetailsViewClass. (the full path to the class file, namespace.class of the newly created class file.

3 comments

Where do I find items for custom modules created using module builder? I found an item Toolboxes/PageControls/Sections/ContetnToolboxSection/Telerik.Sitefinity.DynamicTypes.Employees.Employee (in my case) which has DefaultMasterTemplateKey & DefaultDetailTemplateKey. How can I use this? There is also a node in ContentView but only for backend templates. I really need to add custom logic for custom modules.

Stan Jun 20, 2012

For modules built with the Module Builder go to Administration->Settings->Advanced->DynamicModules and there will be an entry for your module (Telerik.Sitefinity.DynamicTypes.Employees.Employee) when you expand it you will see all of its views as described in the blog post

ming Feb 20, 2013

Toward the end of the article, you mentioned:

>To use the new DetailsView register it in the same box ViewType.SitefintiyWebApp.CustomDetailsViewClass. (the full path to the class file, namespace.class of the newly created class file.

Tools

Sitefinity Professional Services

Progress, Telerik, Sitefinity and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries.