Add a widget in the toolbox

To use custom widgets on a Sitefinity page, you must register them in the toolbox. Once you do this, the widgets are available for drag-and-drop in the page editor user interface.

There are several ways you can register a widget. All of them require a ControlType parameter. The value of this parameter depends on the type of widget used.

  • When registering a custom widget, built into an assembly, the parameter is the fully qualified type name of the widget.
  • When registering a user widget, the parameter is the virtual URL of the user widget.

Register a widget using Sitefinity Thunder

You can register a widget automatically, using Sitefinity Thunder. For more information, see Registering a widget.

Register a widget through the advanced settings

To register a widget using Sitefinity backend, perform procedure Registering a new widget in Sitefinity.

Register a widget through the configuration file

When you use the advanced settings in Sitefinity backend, the settings are persisted in the configuration. By default, these are stored as physical files in folder ~/App_Data/Sitefinity/Configuration of your web project. 

Instead of using the UI, to register a widget, you can manually edit the configuration files. The toolbox configurations have their own separate file, named ToolboxesConfig.config.

Perform the following:
  1. To register a new widget, open the ToolboxesConfig.config file.
  2. Find the section you want to use, or create a new section under the <sections> element.
    • If you are working with a custom widget, register it with the following snippet:
      <add enabled="True" type="~/MyControls/MyUserControl.ascx" title="My User Control" visibilityMode="None" name="MyUserControl" />
    • If you are working with a user widget, register it with the following snippet:
      <add enabled="True" type="MyAssembly.MyNamespace.MyCustomWidget, MyAssembly" title="My custom widget" description="A sample custom control"name="MyCustomControl" visibilityMode="None" />
  3. Save the file and restart the application.

Register a widget through code using the Configuration API

You may want to register your custom widget in the toolbox through the API, if, for example, the widget is part of a custom module and must be registered when the module is installed. 

To register a widget with Sitefinity configuration API, use the following code:

var configManager = ConfigManager.GetManager();
var config = configManager.GetSection<ToolboxesConfig>();
  
var controls = config.Toolboxes["PageControls"];
var sectionName = "MySection";
var section = controls.Sections.Where<ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();
  
if (section == null)
{
    section = new ToolboxSection(controls.Sections)
    {
        Name = sectionName,
        Title = sectionName,
        Description = sectionName,
        ResourceClassId = typeof(PageResources).Name
    };
    controls.Sections.Add(section);
}
  
var controlName = "MyControl";
var controlType = typeof(MyControl);
if (!section.Tools.Any<ToolboxItem>(e => e.Name == controlName))
{
    var tool = new ToolboxItem(section.Tools)
    {
        Name = controlName,
        Title = controlName,
        Description = controlName,
        ControlType = controlType.AssemblyQualifiedName
    };
    section.Tools.Add(tool);
}
  
configManager.SaveSection(config);

In the snippet above, to reflect your custom widget values, you must change the name of the section, the name of the widget, and the type of the widget.

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK