Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.MakeTabAvailable(contextualTabId);
            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
add comment

1 Answer 1

up vote 0 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;
    elem.parentNode.click(); 
    WpClick(dummyevent);
   }

Hope this helps.

share|improve this answer
add comment

Your Answer

 
discard

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.