Displaying context menus in transformations

When writing transformations for displaying Users or Groups, you can enclose the transformation into a container control that provides a context menu triggered by right-clicking a user or group. You can see a live example of these context menus on the sample Community site:

  • Right-click one of the users listed in the Members section.
  • Right-click one of the groups listed in the Groups section.

How is this achieved? If you view the transformation code in the Users viewer or Groups viewer web parts (used for displaying users and groups), you can see that the transformation is enclosed inside a container control.

On this page

Writing transformations for user context menus

To add the context menu to lists of users, enclose your transformation inside the cms:usermenucontainer control (edit the transformation used by the component that displays the list of users):

<cms:usermenucontainer runat="server" ID="userMenuElem" MenuID="userContextMenu" Parameter='<%# Eval("UserID").ToString() %>' ContextMenuCssClass="UserContextMenu" >

... transformation code ...

</cms:usermenucontainer>

Writing transformations for group context menus

To add the context menu to lists of groups, you need to enclose your transformation inside the cms:groupmenucontainer control (edit the transformation used by the component that displays the list of groups):

<cms:groupmenucontainer runat="server" ID="groupMenuElem" MenuID="groupContextMenu" Parameter='<%# Eval("GroupID").ToString() %>' ContextMenuCssClass="UserContextMenu" >

... transformation code ...

</cms:groupmenucontainer>

Note: You can only add controls into transformations of the ASCX type. The system does not render context menu controls in the other transformation types.

Modifying the context menu design

The default controls used for context menus are stored in <web project>\CMSAdminControls\ContextMenus:

  • GroupContextMenu.ascx
  • UserContextMenu.ascx

These two controls are used automatically for the Group or User context menus. If you want to modify the design of the context menus, edit the controls in Visual Studio.

You can also develop custom context menu controls. In this case, you need to add the MenuControlPath parameter to the cms:usermenucontainer or cms:groupmenucontainer controls in the transformation and set its value to the path to your control:

<cms:groupmenucontainer runat="server" ID="groupMenuElem" MenuID="groupContextMenu" Parameter='<%# Eval("GroupID").ToString() %>' ContextMenuCssClass="UserContextMenu" MenuControlPath="~\CMSAdminControls\ContextMenus\MyGroupContextMenu.ascx" >

... transformation code ...

</cms:groupmenucontainer>

Was this page helpful?