2

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?

6

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.

  • I had to add something to make it work: – Kevin .NET Sep 7 '17 at 20:00
2

I had to add window.onload to make Shkipper's answer work:

<script unselectable="on">
  window.onload = function(){
  var elem = document.getElementById("MSOZoneCell_WebPartWPQ2");
  if (elem != null) {
      var dummyevent = new Array();
      dummyevent["target"] = elem;
      dummyevent["srcElement"] = elem;
      elem.parentNode.click(); 
      WpClick(dummyevent);
// Below code will click browse

document.getElementsByClassName("ms-cui-tt-span")[0].click();
   }
}
</script>
  • This will default open the respective ribbon. added document.getElementsByClassName("ms-cui-tt-span")[0].click(); in code to stop this behavior. – love thakker Aug 23 '18 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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