August 6, 2012

SharePoint 2010: Set Default Ribbon Tab on Page Load

Say you need to set the default Ribbon tab when page is loaded, and you want to do it in code-behind, this is how it is accomplished, in your Page_Load method for SharePoint page being rendered:

if (Request.QueryString["InitialTabId"] == null)
    var nameValues = HttpUtility.ParseQueryString(Request.QueryString.ToString());
    nameValues.Set("InitialTabId", SPRibbon.ReadTabId);
    Response.Redirect(string.Format("{0}?{1}", Request.Url.AbsolutePath, nameValues));

This will make sure the browse tab is selected by default on page load. Nice and quick! If you know of a better way to do it from code, please let me know, as I have tried the InitialTabId stuff from MSDN and it didn’t work for me.

1 comment:

  1. great job, thank you! I also couldn't make it another way