Wednesday, November 30, 2005 8:15 AM
by
nick
Context Menu
Here is a little menu control I found yesterday that's pretty handy. I wanted a quick "function menu" that would behave like the ones you see on http://my.msn.com. I also wanted it to have a clean event handling model (not the URL-based type that are so common in menu controls). I found this
Cutting Edge article and code by Dino Esposito that almost did the trick. I tweaked the source code a bit so that “icons” could also be added to the menu (css background style) and modified a few other things.


Here is a final product in action on a scheduling control I’m working on. The image shown is the menu as seen by someone with an ‘admin’ role.
Once you've included the library/dll in the right place, you can easily create the menu with some markup in your ascx/aspx as seen here:
<cc1:contextmenu id="cmFunctions" runat="server" Width="100px" ForeColor="Black"
Font-Names="Tahoma" Font-Size="8pt" AutoHide="False" CellPadding="1">
<cc1:ContextMenuItem Icon="images/menu/availability.gif" Text="Availability"
CommandName="Availability"
Tooltip="Click here to edit your availability"></cc1:ContextMenuItem>
<cc1:ContextMenuItem></cc1:ContextMenuItem>
<cc1:ContextMenuItem Icon="images/menu/refresh.gif" Text="Refresh" CommandName="Refresh"
Tooltip="Click to refresh the calendar"></cc1:ContextMenuItem>
</cc1:contextmenu>
Handling the user's selection event is like normal event handling:
private void cmFunctions_ItemCommand(object sender, CommandEventArgs e)
{
Response.Write(e.CommandName);
}