Home > chrome, MOSS, webpart > Customizing Web part shortcut menu (chrome)

Customizing Web part shortcut menu (chrome)

Web part shortcut menu allows you to minimize, Close, Modify web part and export. To add new item, edit or modify existing item in menu you need to override CreateWebpartmenu method of WebPart base class and access the MenuItems collection of the Web Part’s WebPartMenu property.
List of Item IDs
• MSOMenu_Minimize
• MSOMenu_Restore
• MSOMenu_Close
• MSOMenu_Delete
• MSOMenu_Edit
• MSOMenu_Connections
• MSOMenu_Export
• MSOMenu_Help

Sample example

public override void CreateWebPartMenu()
MenuItem ParentItem, Item1, Item2;

//first we create three menu items
//one as a parent item, and two submenu items
//create the parent item

ParentItem = new MenuItem("ParentItem", "", "ParentItemID");

//create a submenu item with a server event on click
Item1 = new MenuItem("Item1", "Item1ID", new EventHandler(EventHandlerForItem1));

//create a submenu item with a client event on click
Item2 = new MenuItem("Item2", "javascript:alert('Item2 was clicked');", "Item2ID");
// We then add the submenu items to the parent item.


// We then decide that we'd like to add the parent item after the
// "Edit Web Part Properties" item in the menu.
// First we find the index of the "Edit" item
int EditIndex =

// Then we insert the parent item after the "Edit" item
this.WebPartMenu.MenuItems.Insert(EditIndex + 1, ParentItem);

// Make sure the parent item has a separator above it
ParentItem.BeginSection = true;

// Check a custom property to decide whether to display the parent menu
if (this.CustomProperty1 == true)
ParentItem.Visible = true;
ParentItem.Visible = false;
// Check another custom property to decide which menu item to enable
// within the parent item
if (this.CustomProperty2 == true)
Item1.Enabled = true;
Item2.Enabled = false;
Item1.Enabled = false;
Item2.Enabled = true;
Categories: chrome, MOSS, webpart
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: