.NET Tips and Tricks

Blog archive

Guru Tip: How to Activate a SharePoint Ribbon Tab in Sandboxed Solutions

I went back to Andrei Smolin, a team leader at Add-In Express, for some more SharePoint help. I wanted to activate a Ribbon Tab using, I thought, code like this:

SPRibbon  currentRibbon = SPRibbon.GetCurrent(this.Page);
currentRibbon.MakeTabAvailable("<Tab  Id>");
currentRibbon.InitialTabId  = "<Tab Id>";

Unfortunately, I wanted to use this code in a Sandboxed solution -- something that's specifically forbidden. Andrie pointed out that my code wouldn't work very well in a farm solution, either: the tab would get selected but it wouldn't get activated.

Andrie gave me the following script, which not only bypasses the Sandbox limitation but actually activates the tab. This code works with a feature called SPRibbon and a tab with the ID AdxspRibbonTab1, so you'll need to change those two names in your code:

var ribbonReady = false;

function onBodyLoaded() {
  if (!ribbonReady) {
    if ((typeof (_ribbonReadyForInit) == 'function') &&
         _ribbonReadyForInit()) {
      ribbonReady = true;
      var control = get_SPRibbon().FindControl("AdxspRibbonTab1");
      if (control != null) {
        var tabElem = document.getElementById(control.getFullId() +
        if (tabElem && tabElem.firstChild) {

if (_spBodyOnLoadFunctionNames != 'undefined' && 
    _spBodyOnLoadFunctionNames != null) {

Posted by Peter Vogel on 05/17/2012 at 1:16 PM

comments powered by Disqus


  • Microsoft's Tools to Fight Solorigate Attack Are Now Open Source

    Microsoft open sourced homegrown tools it used to check its systems for code related to the recent massive breach of supply chains that the company has named Solorigate.

  • Microsoft's Lander on Blazor Desktop: 'I Don't See a Grand Unified App Model in the Future'

    For all of the talk of unifying the disparate ecosystem of Microsoft-centric developer tooling -- using one framework for apps of all types on all platforms -- Blazor Desktop is not the answer. There isn't one.

  • Firm Automates Legacy Web Forms-to-ASP.NET Core Conversions

    Migration technology uses the Angular web framework and Progress Kendo UI user interface elements to convert ASP.NET Web Forms client code to HTML and CSS, with application business logic converted automatically to ASP.NET Core.

  • New TypeScript 4.2 Tweaks Include Project Explainer

    Microsoft shipped TypeScript 4.2 -- the regular quarterly update to the open source programming language that improves JavaScript with static types -- with a host of tweaks including a way to explain why files are included in a project.

Upcoming Events