Building a widget for 4.2 - what is the most up to date exam

Posted by Community Admin on 03-Aug-2018 19:19

Building a widget for 4.2 - what is the most up to date example?

All Replies

Posted by Community Admin on 18-Aug-2011 00:00

I am building a simple widget for Sitefinity 4.2 toolbox based on a user control that includes a widget designer so a back end user can configure the widget.

Can anyone point me to the most up to date example (meaning 4.2 compatible) or documentation of building a widget for the toolbox?

I've built some widgets for 4.0 and 4.1, but I want to make sure that I'm following the very latest best practices.

Thank you,
Dan Sorensen
Vancouver, WA

Posted by Community Admin on 18-Aug-2011 00:00

I'm still mainly looking for current documentation as stated above, but to clarify why I'm looking for it, here are the current steps I follow to create a custom widget. Is this way still recommended? Are there any alternate or easier ways?

Task: create a widget that outputs a copyright symbol and the current year and a user provided string such as "copyright [our company], all rights reserved."

Purpose: To always have an up to date year in our copyright message in the footer of user designed templates.

Steps:
1. In Visual Studio - create a new folder for the widget
2. Create Widget.ascx & the codebehind Widget.ascx.cs
3. Add my code to create the widget.
4. Create WidgetDesigner.cs - add some boilerplate Sitefinity designer code
5. Create WidgetDesigner.js - add some boilerplate Sitefinity designer js code
6. Create WidgetDesignerTemplate.ascx - add some boilerplate Sitefinity html
7. Compile
8. Register the widget (user control) in Administration > Advanced > Toolbox
9. Test via the user back end screens and hope I didn't break anything too badly.

If that is still correct, I'm ok. Although, I wish that steps 4-6 were more straight forward. The boilerplate code is pretty verbose and difficult to work with other than copy/paste, rename a couple variables to match my user control's name and properties.

Step 8 works fine, although it's never easy to remember what needs to be typed in there. Can this be done with a config file instead?

For step 9, I wish there was a standalone simplified sitefinity page project that I could load my custom widget into simply for testing. A project that did nothing other than display a sample page for testing widgets. It takes a long time to navigate to a page for testing.

Posted by Community Admin on 18-Aug-2011 00:00

It looks like the 4.2 developer documentation does have quite a bit on the topic: 
http://www.sitefinity.com/40/help/developers-guide/sitefinity-essentials-controls-working-with-control-designers.html

If you have more sources, I'm interested in reading some examples. I'm sorry if I wasted anyone's time. In 4.0 I had to track down the information in a blog article somewhere rather than in the Sitefinity Docs. I had assumed that was still the case.

Posted by Community Admin on 23-Aug-2011 00:00

Hi Dan Sorensen,

Thank you very much for the positive feedback, indeed our Documentation has become much more complete and organized with the last two major releases. Along with it I'd recommend you to take a look at the Sitefinity SDK which offers several complete code samples ranging from simple controls to advanced modules. The Tutorials section from our online Documentation is another valuable resource that you might refer to along with the SDK.
I'd like to comment a little bit on the workflow you have outlined in the previous response - indeed this is the correct way to create a custom control for Sitefinity, however you are not obliged to stick to that format when it comes to some widgets requiring simple functionality. If you are not required to have custom designer for your control, you can still expose some properties in the default one, and end up with a simple user control consisting of a template (*.ascx), codefile (*.cs) and the automatically generated designer(*.ascx.designer.cs)
and thus skip steps 4-6 . Say for instance our NewsRotator sample is a good example of a Sitefinity widget that does not require custom designer. If there's anything else you'd like to know, please do not hesitate to ask.

Regards,
Boyan Barnev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

This thread is closed