Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8012733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:25:02+00:00 2026-06-04T19:25:02+00:00

The Sitecore PageEditor and Preview interfaces feature a language selector button that triggers a

  • 0

The Sitecore PageEditor and Preview interfaces feature a language selector button that triggers a “dropdown”/overlay menu where the user can select a language. How do I replicate this behavior?

(I set out to answer this question, and came up with a solution. Posting to SOF for comment/enhancement.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:25:04+00:00Added an answer on June 4, 2026 at 7:25 pm

    You can see how Sitecore does it in the Sitecore.Client assembly, Sitecore.Shell.Applications.WebEdit.Commands.ChangeLanguage and Sitecore.Shell.Applications.WebEdit.Commands.SetLanguage.

    You’ll need to create two commands of your own for this. One command is associated with the button, one is executed when a subitem is selected. The example is based on a scenario of changing a country cookie.

    ChangeCountry Command

    First, the command to display the menu. You can see that it displays a Menu with dynamic options. Overriding GetHeader and GetIcon allows the button itself to be dynamic based on the user’s current selection.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Sitecore.Shell.Applications.WebEdit.Commands;
    using Sitecore.Diagnostics;
    using Sitecore.Data.Items;
    using Sitecore.Web.UI.Sheer;
    using Sitecore.Web.UI.HtmlControls;
    using Sitecore.StringExtensions;
    using System.Web;
    
    namespace Prototype.Commands
    {
        public class ChangeCountry : WebEditCommand
        {
            protected Dictionary<string, CountryOption> _countries = new Dictionary<string, CountryOption>
            {
                {"US", new CountryOption {
                    ID = "US",
                    Name = "United States",
                    Icon = "Flags/32x32/flag_usa.png"
                }},
                {"CA", new CountryOption {
                    ID = "CA",
                    Name = "Canada",
                    Icon = "Flags/32x32/flag_canada.png"
                }},
                {"MX", new CountryOption {
                    ID = "MX",
                    Name = "Mexico",
                    Icon = "Flags/32x32/flag_mexico.png"
                }},
                {"DE", new CountryOption {
                    ID = "DE",
                    Name = "Germany",
                    Icon = "Flags/32x32/flag_germany.png"
                }}
            };
    
            public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
            {
                Assert.ArgumentNotNull(context, "context");
                if (context.Items.Length == 1)
                {
                    Item item = context.Items[0];
                    SheerResponse.DisableOutput();
                    Menu control = new Menu();
                    //replace with lookup and loop of available values
                    foreach (var key in _countries.Keys)
                    {
                        var country = _countries[key];
                        string id = country.ID;
                        string header = country.Name;
                        string icon = country.Icon;
                        string click = "prototype:setcountry(country={0})".FormatWith(key);
                        control.Add(id, header, icon, string.Empty, click, false, string.Empty, MenuItemType.Normal);
                    }
                    SheerResponse.EnableOutput();
                    SheerResponse.ShowPopup("ChangeCountryButton", "below", control);
                }
            }
    
            public override string GetHeader(Sitecore.Shell.Framework.Commands.CommandContext context, string header)
            {
                HttpCookie country = HttpContext.Current.Request.Cookies["country"];
                if (country != null && _countries.ContainsKey(country.Value))
                {
                    return _countries[country.Value].Name;
                }
                return base.GetHeader(context, header);
            }
    
            public override string GetIcon(Sitecore.Shell.Framework.Commands.CommandContext context, string icon)
            {
                HttpCookie country = HttpContext.Current.Request.Cookies["country"];
                if (country != null && _countries.ContainsKey(country.Value))
                {
                    return _countries[country.Value].Icon;
                }
                return base.GetIcon(context, icon);
            }
    
            protected class CountryOption
            {
                public string ID { get; set; }
                public string Name { get; set; }
                public string Icon { get; set; }
            }
        }
    }
    

    In either Commands.config or an include file, register the new command.

    <command name="prototype:changecountry" type="Prototype.Commands.ChangeCountry,Prototype" />
    

    Change Country Button

    Create a new Chunk and Button under /sitecore/content/Applications/WebEdit/Ribbons/WebEdit/Experience. This ribbon strip is referenced/replicated in Preview mode as well. The button will use the following properties:

    Ribbon Button

    The Click field must match the name of your command, and the ID field must match the element ID provided in the SheerResponse.ShowPopup call above.

    SetCountry Command

    Next is the command that will be called when an item in your menu/dropdown is selected.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Sitecore.Shell.Applications.WebEdit.Commands;
    using System.Net;
    using Sitecore.Diagnostics;
    using Sitecore.Web.UI.Sheer;
    using System.Web;
    
    namespace Prototype.Commands
    {
        public class SetCountry : WebEditCommand
        {
            public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
            {
                Assert.ArgumentNotNull(context, "context");
                var country = context.Parameters["country"];
                Assert.IsNotNullOrEmpty(country, "Country not found");
                HttpCookie cookie = new HttpCookie("country", country);
                HttpContext.Current.Response.Cookies.Add(cookie);
                WebEditCommand.Reload(WebEditCommand.GetUrl());
            }
        }
    }
    

    In our example, we’re setting a cookie based on the selected value and reloading the page. The value passed in is based on the click event associated with the menu item in ChangeCountry. Likewise, the name of the command when configured needs to match what was used in the ChangeCountry click event.

    <command name="prototype:setcountry" type="Prototype.Commands.SetCountry,Prototype" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Sitecore/ASP.NET projects that I'm developing. Today at some point I inadvertently
I am writing an page inside Sitecore where users can create Sitecore items by
In Sitecore how can I access all statically bound sublayouts from the code behind
How can I login programmatically into Sitecore? For example if you would like to
I have user control under Sitecore CMS. It has some controls bound to some
In Sitecore 6, I have created a sublayout that has an asp:login control. For
The Sitecore Calendar Module doesn't have the features that we want: recurring events, multiple
I have a Sitecore content structure where any single item can have a number
In a Sitecore Treelist or Multilist, items available for selection and items that have
I am using a debug device in sitecore (6) that will output a 'developer'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.