Skip to Main Content
Essential SharePoint 2007, 2nd Edition
book

Essential SharePoint 2007, 2nd Edition

by Jeff Webb
September 2007
Beginner content levelBeginner
448 pages
10h 2m
English
O'Reilly Media, Inc.
Content preview from Essential SharePoint 2007, 2nd Edition

Adding Menus

To add a menu to a web part, override the Verbs property to add WebPartVerb objects to the web part's WebPartVerbCollection. Web part menus can respond to events with server-side code, client-side code, or both. The following example adds two menu items to a web part:

  • The Save Settings item runs server-side code to save the web part properties.

  • The Help item runs JavaScript to display a help page in a new window.

public override WebPartVerbCollection Verbs
{
  get
  {
         // Create a list to hold the verbs.
         ArrayList verbSet = new ArrayList(  );
         // Add the built-in verbs to the list.
         verbSet.AddRange(base.Verbs);
         // Create a custom server-side verb.
         WebPartVerb vSave = new WebPartVerb("vSave",
           new WebPartEventHandler(vSave_Click));
           vSave.Description = "Saves web part properties.";
         vSave.Text = "Save Settings";
         // Add it to the list of verbs.
         verbSet.Add(vSave);
         // Create a custom client-side verb.
         WebPartVerb vHelp = new WebPartVerb("vHelp",
            "javascript:window.open('page1.aspx','_help',
            'height=200,width=200');");
         vHelp.Description = "Show Help in new window.";
         vHelp.Text = "Help";
        // Add it to the list of verbs.
         verbSet.Add(vHelp);

         // Return the new list.
         return new WebPartVerbCollection(verbSet);
  }
 }

protected void vSave_Click(object sender, WebPartEventArgs e)
{
  this.SetPersonalizationDirty( );
}

Figure 11-14 shows the web part menu in action.

Adding a menu item to a web part

Figure 11-14. Adding a menu item to ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft® Office SharePoint® Server 2007 Best Practices

Microsoft® Office SharePoint® Server 2007 Best Practices

Ben Curry, Bill English
SharePoint 2007: The Definitive Guide

SharePoint 2007: The Definitive Guide

James Pyles, Christopher M. Buechler, Bob Fox, Murray Gordon, Michael Lotter, Jason Medero, Nilesh Mehta, Joris Poelmans, Christopher Pragash, Piotr Prussak, Christopher J. Regan

Publisher Resources

ISBN: 9780596514075Errata Page