Reordering Controls In Sitefinity Page Toolboxes

Default Blog Top Image
by Stanislav Velikov Posted on January 09, 2014
The content you're reading is getting on in years.

This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

This blog post provides a sample of reordering Sitefinity page toolbox controls through the configuration API.

Here is a sample web form that contains this sample code which reverses the order of the toolbox control in the preselected section. A video of how the reordering function works is available here.

The approach is to load all toolbox sections registered in the site, both built-in and custom control sections. This will retrieve an instance of ConfigManager using Config.GetManager()
and then retrieve ToolboxesConfig that contains toolboxes for PageControls, LayoutControls and FormsControls (for the Sitefinity forms module).

  var configManager = Config.GetManager();
            var toolboxConfig = configManager.GetSection<ToolboxesConfig>();
 
var retrieveSectionNames = toolboxConfig.Toolboxes["PageControls"]
                                                                      .Sections.ToList<ToolboxSection>().Select(s => s.Name);

The above code will return the names of all toolbox sections in the site.

Once a section is selected, get all controls from this section which are to be reordered:

var toolboxItems = toolboxConfig.Toolboxes["PageControls"]
                                                 .Sections.ToList<ToolboxSection>()
                                                    .Where(g => g.Name =="NavigationControls")
                                                                       .FirstOrDefault().Tools;

Once the controls section is retrieved save the retrieved controls in a new variable "originalConfigs" and perform the reordering there (I am reversing the order). After this remove the whole tools collection from the original toolbox and add the reordered controls:

var originalConfigs = toolboxItems.Reverse<ToolboxItem>().ToList<ToolboxItem>();
 
           //remove all controls from the section
           while (toolboxItems.Count > 0)
           {
               toolboxItems.RemoveAt(0);
           }
 
           configManager.SaveSection(toolboxConfig);
 
           //add the ordered controls back to the section
           foreach (var item in originalConfigs)
           {
               toolboxItems.Add(item);
           }
           configManager.SaveSection(toolboxConfig);


Stanislav Velikov
Stanislav Velikov is a Tech Support Engineer at Telerik. He joined the Sitefinity Support team in April 2011.
More from the author

Related Products:

Sitefinity

Digital content and experience management suite of intelligent, ROI-driving tools for marketers and an extensible toolset for developers to create engaging, cross-platform digital experiences.

Get started
Prefooter Dots
Subscribe Icon

Latest Stories in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation