SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Basically my questiong is regarding the ribbon.

So I want to have the following behaviour, when a person clicks on the button, the contextual ribbon tab should be opened.

Any idea how to do that?

I have the following code:

            SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
            string contextualTabId = ribbonItems[listType];         
            ribbon.MakeContextualGroupInitiallyVisible(contextualTabId, string.Empty);

But the problem is it disappeares after a second.

Another solution might be to focus the web part but how to do it from c#? I tried with js but was not a good solution. And it didn't work very well either.

So any idea?

share|improve this question
up vote 3 down vote accepted

Basically I've still succeeded to fix my problem by using the JavaScript.

Here is the code:

var elem = document.getElementById("MSOZoneCell_WebPartWPQ2");
if (elem != null) {
    var dummyevent = new Array();
    dummyevent["target"] = elem;
    dummyevent["srcElement"] = elem;; 

Hope this helps.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.