Try Now
More in this section
Blogs RSS feed

Command panel: Using multiple command panels

by Ivan Osmak

[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]

With the new backend architecture introduced in Sitefinity 3.6 we have introduced an ability to use multiple command panels in a module. The benefits of this approach include following:
  • You can decouple your command panels which makes it easier to inherit and modify them
  • You can group commands into logical units and hide or show them as you see fit
  • You are able to take advantage of conditional command panel loading, which means that you can easily implement logic on which your code will decide which command panels to load
As it was explained in the other articles in this topic, you have variety of options when it comes to creating command panels. You can generate command panels automatically, manually, load whole controls as command panels, regardless if they are User Controls or Custom Controls. What’s even more, you can combine different approaches and for example load command automatically, load a special command panel through a User Control and two other command panels as Custom Controls.


How to add multiple command panels

When you are generating commands automatically, all your commands are being added to one default command panel. You can turn this feature on or off as explained in this article.


If you are adding command panels manually or by loading Custom Controls, you can add any number of command panels to the list parameter of the method you are overriding.

/// <summary>   
/// Creates the custom command panels.   
/// </summary>   
/// <param name="viewMode">The view mode.</param>   
/// <param name="list">The list.</param>   
protected override void CreateCustomCommandPanels(string viewMode, System.Collections.Generic.List<Telerik.Web.ICommandPanel> list)   
     list.Add(new BooksCommandPanel(this));   
Finally, due to a somewhat special nature of User Controls, the approach for User Control based command panels is slightly different. Instead of adding command panels to the list parameter, you can add any number of virtual paths to the userControls parameter and hence load multiple User Control based command panels.
protected override void CreateCommandPanelsFromUserControls(string viewMode, System.Collections.Generic.List<string> userControls, System.Collections.Generic.List<Telerik.Web.ICommandPanel> list)   
      if (userControls == null
                  userControls = new List<string>(); 
      base.CreateCommandPanelsFromUserControls(viewMode, userControls, list);   


Order of command panels

If you are using one single approach to create command panels (automatic, manually, user controls or custom controls) you are in complete control of the order of command panels and commands; namely they will appear in the same order as you add them to the collections of command panels.
On the other hand, if you are mixing different approaches you should bear in mind that command panels will be loaded in regard to way that they were created and do so like this:
  • Automatically generated commands will be generated first
  • After automatically generated commands, manually created command panels will be loaded
  • After manually created commands, User Control based command panels will be loaded
  • Finally, command panels based on Custom Controls will be loaded
Once again, if the order of command panels is absolutely important to you, you should pick only one of the approaches for creating command panels and add command panels to the collection in order in which you wish them to be displayed.

Leave a comment