SharePoint All The Time

December 30, 2008

Redesigning the Site Actions Control

Filed under: Design, Workaround — sharepointguys @ 12:41 am

The default Sharepoint Site Actions control doesn’t really blend well with custom designs.

We could use our own CSS styles to override the colors and styles, but the arrow on the right is an IMG element and is hardcoded within the default site actions control to “whitearrow.gif”. Therefore changing this image isn’t quite possible through CSS.

Here’s a workaround to that.

The default site actions webcontrol is in this class Microsoft.SharePoint.WebControls.SiteActions. Fortunately this class isn’t locked down and we can cheat a little to change the image.

Let’s try to change the image to “menudark.gif”.

Here’s the code snippet to acheive that.

namespace Custom
{
  public class SiteActions : Microsoft.SharePoint.WebControls.SiteActions
  {
    public override void RenderControl(HtmlTextWriter writer)
    {
      Control ctrlParentZero = null;

      if (Controls.Count > 0)
      {
        ctrlParentZero = Controls[0];
        int count = ctrlParentZero.Controls.Count;

        for (int i = 0; i < count; i++)
        {
          Control ctrl = ctrlParentZero.Controls[i];
          if (ctrl.GetType() == typeof(Microsoft.SharePoint.WebControls.Menu))
          {
            Microsoft.SharePoint.WebControls.Menu menu
              = ctrl as Microsoft.SharePoint.WebControls.Menu;
            menu.ArrowImageUrl = "/_layouts/images/menudark.gif";
          }
        }
      }
      base.RenderControl(writer);
    }
  }
}

That’s not all. There’s a second part to this workaround. We need to create a Sharepoint ControlTemplate based on “PublishingActionMenu.ascx”. We shall name our ControlTemplate “CustomActionMenu.ascx” that uses our Custom Site Action class. (Remember to sign and add our own site actions webcontrol to the GAC.)

<%@ Control Language="C#" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Custom" Namespace="Custom" Assembly="Custom, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c1e73a244135d918" %>

<Custom:SiteActions runat="server" AccessKey="<%$Resources:wss,tb_SiteActions_AK%>" id="SiteActionsMenuMain"
  PrefixHtml="&lt;div&gt;"
  SuffixHtml="&lt;/div&gt;"
  MenuNotVisibleHtml="&amp;nbsp;">
  <CustomTemplate>
    <SharePoint:FeatureMenuTemplate runat="server"
      FeatureScope="Site"
      Location="Microsoft.SharePoint.StandardMenu"
      GroupId="SiteActions"
      UseShortId="true">
      <SharePoint:MenuItemTemplate runat="server" id="MenuItem_Create"
        Text="<%$Resources:wss,viewlsts_pagetitle_create%>"
        Description="<%$Resources:wss,siteactions_createdescription%>"
        ImageUrl="/_layouts/images/Actionscreate.gif"
        MenuGroupId="100"
        Sequence="100"
        UseShortId="true"
        ClientOnClickNavigateUrl="~site/_layouts/create.aspx"
        PermissionsString="ManageLists, ManageSubwebs"
        PermissionMode="Any" />
      <SharePoint:MenuItemTemplate runat="server" id="MenuItem_EditPage"
        Text="<%$Resources:wss,siteactions_editpage%>"
        Description="<%$Resources:wss,siteactions_editpagedescription%>"
        ImageUrl="/_layouts/images/ActionsEditPage.gif"
        MenuGroupId="100"
        Sequence="200"
        ClientOnClickNavigateUrl="javascript:MSOLayout_ChangeLayoutMode(false);" />
      <SharePoint:MenuItemTemplate runat="server" id="MenuItem_Settings"
        Text="<%$Resources:wss,settings_pagetitle%>"
        Description="<%$Resources:wss,siteactions_sitesettingsdescription%>"
        ImageUrl="/_layouts/images/ActionsSettings.gif"
        MenuGroupId="100"
        Sequence="300"
        UseShortId="true"
        ClientOnClickNavigateUrl="~site/_layouts/settings.aspx"
        PermissionsString="EnumeratePermissions,ManageWeb,ManageSubwebs,AddAndCustomizePages,ApplyThemeAndBorder,ManageAlerts,ManageLists,ViewUsageData"
        PermissionMode="Any" />
    </SharePoint:FeatureMenuTemplate>
  </CustomTemplate>
</Custom:SiteActions>

Finally, we’ll have to update our masterpage to use our own “CustomActionMenu.ascx” ControlTemplate.

That’s it. We now have a clean site action menu control to skin.

Advertisements

6 Comments »

  1. can you know what is Location and GroupId for in FeatureMenuTemplate?
    and how can i use it from code (C#)?
    thank in advance

    Comment by Pr0fess0rX — January 1, 2009 @ 12:39 am

  2. Hi Pr0fess0rX,

    <SharePoint:FeatureMenuTemplate runat=”server”
    FeatureScope=”Site”
    Location=”Microsoft.SharePoint.StandardMenu”
    GroupId=”SiteActions”

    Basically it tells you this Menu is the SiteActions Menu and Edit Page, Create Page and Create Site etc will show. For more information, please visit this link
    http://msdn.microsoft.com/en-us/library/bb802730.aspx
    http://msdn.microsoft.com/en-us/library/ms460194.aspx

    Comment by sharepointguys — January 5, 2009 @ 10:35 am

  3. Interesting, but usual =)

    Comment by jason kenny — January 17, 2009 @ 1:11 am

  4. I can’t believe it’s so complicated to change that arrow.

    Comment by Carl von Buelow — February 14, 2009 @ 7:30 am

  5. […] “Redesigning the Site Actions Control” […]

    Pingback by the rasx() context » Blog Archive » SharePoint Links out of the TODO List — April 4, 2009 @ 12:36 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: