Building A Ribbon Tab Loading WebPart

I recently had the requirement where I was building a custom contextual group in the 2010 ribbon tab. By default, as an admin, SharePoint appears to choose which ribbon it uses in simple cardinal order. But, it is fairly easy to get around this limitation. In the PreRender event of a WebPart, just slap in this code:

[csharp]

 protected override void OnPreRender(EventArgs e)
        {
            SPRibbon ribbon = SPRibbon.GetCurrent(Page);
            if (ribbon != null)
            {
                ribbon.Minimized = false;
                ribbon.CommandUIVisible = true;
                const string initialTabId = “[Put your tab ID here]”;
                if (!ribbon.IsTabAvailable(initialTabId))
                {
                    ribbon.MakeTabAvailable(initialTabId);
                }
                ribbon.InitialTabId = initialTabId;
            }
            base.OnPreRender(e);
        }

[/csharp]

easy peasy.

Share

One thought on “Building A Ribbon Tab Loading WebPart”

Leave a Reply

Your email address will not be published. Required fields are marked *