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

I have a webpart page with two webparts. One is a calendar and the other is a hidden content query webpart that references a file that is used to style (apply color coding) to the calendar entries.

My problem is that when the user goes to the page the calendar ribbon is not available. This occurs because there are two webparts on the page and the ribbon doesn't know which one it needs to use to generate its content. How can I force my calendar control to always be selected when the page loads so that my users have access to the calendar ribbon without having to click on the calendar?

share|improve this question
up vote 6 down vote accepted

1 Make sure jQuery is present and working on the page in question - I found I had to download from the jQuery site ( and use a relative link. Using the CDN hosted jQuery didn't work for me.

    <script src="/Shared%20Documents/jquery.js" type="text/javascript"></script>

This link was useful -

2 Add a content editor web part to the page with this code:

 <script language="javascript" type="text/javascript">

    $(document).ready(function  () {

       ExecuteOrDelayUntilScriptLoaded(ShowCalendarRibbon, "sp.ribbon.js" );

       function  ShowCalendarRibbon() {

          try  {

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

          catch  (e) {
             alert("Problem initializing ribbon");




N.B. Add this code through the HTML source of the content editor:

enter image description here

You may need to change the ID for the Calendar depending on the web parts on your page, but mine was - MSOZoneCell_WebPartWPQ2

Set "Chrome Type" to "None" to hide the content editor on the page.

This post provided most of the info - Select the ListView Web Part Automatically on AllItems.aspx

This post also helped -

Using a query string is also an option - E.g. ?InitialTabId=Ribbon.Calendar.Calendar - but this didn't seem to work for me

share|improve this answer
Thanks! This worked perfectly. – skeletank May 16 '12 at 13:04
I've noticed that this doesn't work on some pages where I've added more javascript through other content editors. On those pages it will select the "Calendar Tools" tab on load but the "Calendar" sub tab will not be selected. Are there any timing issues with this code? – skeletank May 30 '12 at 15:40
Hi @skeletank, I haven't been able to replicate your issue, are you able to post some of the other javascript you have on your pages to see if I can get the same thing to happen? – junkrig May 31 '12 at 1:04

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.