Microsoft.SharePoint.WebCon ...


SubMenuTemplate Class (Microsoft.SharePoint.WebControls)

Namespace: Microsoft.SharePoint.WebControls
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)
Syntax

Visual Basic (Declaration)
<DefaultPropertyAttribute("Text")> _
<ParseChildrenAttribute(ChildrenAsProperties:=False)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class SubMenuTemplate
    Inherits Control
    Implements IPreRenderOverride
Visual Basic (Usage)
Dim instance As SubMenuTemplate
C#
[DefaultPropertyAttribute("Text")] 
[ParseChildrenAttribute(ChildrenAsProperties=false)] 
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] 
public class SubMenuTemplate : Control, IPreRenderOverride
Inheritance Hierarchy

System.Object
   System.Web.UI.Control
    Microsoft.SharePoint.WebControls.SubMenuTemplate
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Tags :


Community Content

snorks
Does not appear in wss_minimal.

Using wss_minimal, the menu does not appear in the siteactions area as it does when setting sharepoint to full trust, and I get no error. I've applied a permission with the attributes given in this documentation but it still does not work.. Please help?


Reza Alirezaei - MVP
SubMenuTemplate

Description

Use the SubMenuTemplate class to define a common content and behavior for a submenu of a menu item. The template created using the SubMenuTemplate fills the entire section allocated to a submenu of the menu item. The SubMenuTemplate class becomes handy, when you need to display a specific control within a particular menu item's submenus. Placing a control onto the template container causes the control to be displayed within a submenu when the submenu is invoked.

Usage Scenario

It’s a common requirement that SharePoint developers use CustomActions in their features to customize out of the box SharePoint user interface. For example, you can customize the Site Actions menu by adding menus and submenus to it. The following CAML code snippet is the manifest of a feature that will add a new menu item to the Site Actions menu. This menu is having a reference to a class that acts as the code behind and in turn will render the UI element for the menu item.

<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> 
<CustomAction 
Id="{7352785B-694B-46B7-B92F-C2377CA68C6A}" 
Location="Microsoft.SharePoint.StandardMenu" 
GroupId="SiteActions" 
ControlAssembly="Demo" 
ControlClass="Demo.SDKBountyMenu"> 
</CustomAction> 
</Elements> 

When the feature above gets activated, an extra menu item is added to the Site Actions menu. This new menu item will contain a sub menu pointing to a dummy URL. The SDKBountyMenu class, which is the code behind for the parent menu item, inherits from the WebControl class.

By overriding the CreateChildControls method, you can create two objects of type SubMenuTemplate and MenuItemTemplate, and add them to the Controls collection. The SubMenuItemTemplate instance corresponds with a menu item that contains sub menu item which is in turn an instance of the MenuItemTemplate class. By setting the Text, Description and ImageUrl properties and other properties, you can specify how exactly the menu and its submenu should look like and behave. For example , the ClientOnClickNavigateUrl of the MenuItemTemplate class specifies the URL for the menu item itself.

Code Sample in C#

 public class SDKBountyMenu : System.Web.UI.WebControls.WebControl
{
protected override void CreateChildControls()
{
SubMenuTemplate skdBountyMenu = new SubMenuTemplate();
skdBountyMenu.Text = "SDK Bounty Program";
skdBountyMenu.Description = "A program to help SDK documentation for SharePoint APIs";
skdBountyMenu.ImageUrl = "/_layouts/images/lg_ICASCX.gif";

MenuItemTemplate dummyUrl = new MenuItemTemplate();
dummyUrl.Text = "Be part of Community";
dummyUrl.Description = "Help the community by documenting undocumented API calls.";
dummyUrl.ClientOnClickNavigateUrl = "http://msdn.microsoft.com/en-us/library/bb264594.aspx";
skdBountyMenu.Controls.Add(dummyUrl);
this.Controls.Add(skdBountyMenu);
}
}

Code Sample in VB.NET

Public Class SDKBountyMenu
Inherits System.Web.UI.WebControls.WebControl
Protected Overloads Overrides Sub CreateChildControls()
Dim skdBountyMenu As New SubMenuTemplate()
skdBountyMenu.Text = "SDK Bounty Program"
skdBountyMenu.Description = "A program to help SDK documentation for SharePoint APIs"
skdBountyMenu.ImageUrl = "/_layouts/images/lg_ICASCX.gif"

Dim dummyUrl As New MenuItemTemplate()
dummyUrl.Text = "Be part of Community"
dummyUrl.Description = "Help the community by documenting undocumented API calls."
dummyUrl.ClientOnClickNavigateUrl = "http://msdn.microsoft.com/en-us/library/bb264594.aspx"
skdBountyMenu.Controls.Add(dummyUrl)
Me.Controls.Add(skdBountyMenu)
End Sub
End Class

Suman Chakrabarti [MSFT]
Good examples on creating submenus for SharePoint
  • http://msdn.microsoft.com/en-us/magazine/cc794261.aspx
  • http://docs.teamlink.be/collaborate/PublicBlog/Lists/Posts/Post.aspx?ID=3
  • http://weblogs.asp.net/jan/archive/2008/05/08/creating-hierarchical-menus-with-a-customaction-in-sharepoint.aspx
  • http://www.codekeep.net/snippets/9091b2f1-7601-4749-a594-c5d596def669.aspx

Page view tracker