Common Context menu


Purpose
This sample presents the following scenarios for using and customizing a ContextMenu control:
  • The SimpleMap page shows how to associate a ContextMenu with a Map control. The ContextMenu is visible at design time in the page. The onContextMenu event in the browser displays the ContextMenu at run time. The ItemClicked event on the ContextMenu handles all click events on context menu items.
  • The SimpleToc page shows how to add a ContextMenu to each layer in the table of contents (TOC). Each resource maintains a MapTocFunctionality to render resource and layer content in the TOC. Since the Toc control derives from the TreeViewPlus control, each layer in each MapTocFunctionality is matched to its respective node in the TOC. A ContextMenu control is associated with the node and triggered to display via the onContextMenu event. The ContextMenu contains one context menu item to retrieve and display fields in the active layer.
  • The SimpleTaskResults page shows how to leverage the context menus pre-created by the TaskResult control, work with node events, and add context menus to custom nodes. The TaskResults control creates a set of context menus to support the display of different types of nodes. One such context menu contains context menu items for nodes that reference features (FeatureNodes). The context menu is accessible via the TaskResults.FeatureContextMenu property and can be modified. A custom context menu item that manually removes a node is provided. The NodeRemoved event is handled for the TaskResults control to store properties of the removed node for future use. A Toolbar control is included to illustrate how to create custom TaskResult nodes with context menus.
  • The SimpleTask page is coupled with a custom task in the SimpleTaskContextMenu_<language> App_Code folder. The custom task demonstrates how to create a context menu in a task and add it to results generated by the task and displayed in a TaskResults control.

How to use

If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

At design time
  1. Verify that the Web Application Developer Framework (ADF) for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
  2. In Windows Explorer, navigate to <ArcGIS install location>\DeveloperKit10.0\Samples\ServerNet. This folder contains the Common_ContextMenu with CSharp and VBNet folders.
  3. Open the folder of the language you're going to use—CSharp or VBNet—and copy the Common_ContextMenu_<language> folder to c:\inetpub\wwwroot. The <language> variable can be either CSharp or VBNet.
  4. Start Microsoft Visual Studio 2008 or 2010 and open the Common_ContextMenu_<language><vs_version> solution (for example, Common_ContextMenu_CSharp2008.sln) located in c:\inetpub\wwwroot\Common_ContextMenu_<language>. The <vs_version> references the Visual Studio version of the solution, either 2008 or 2010.
  5. For pages that contain a MapResourceManager, set the map resource item to a valid resource, and reconfigure any tasks present in the page if they need to work with this resource.
  6. In Solution Explorer, right-click the page you want to view, and select Set As Start Page.

At run time
  1. Start the sample application.
  2. In SimpleMap.aspx, right-click the map and select Zoom In.
  3. In SimpleToc.aspx, right-click a layer in the TOC and select Show Fields.
  4. Hover over a layer. The layer text displays in red.
  5. Right-click the background of the layer node. It turns light blue.
  6. Click Show Fields. The background is reset to the original color, and a list of fields is displayed below the Map control.
  7. In SimpleTaskResults.aspx, display the search attributes task dialog, enter a search string, and execute. If the results contain feature nodes (nodes that represent individual features) right-click the node and select Remove or Remove Node. The node is removed. Remove is part of the TaskResults feature context menu while Remove Node was added explicitly.
  8. Click a tool in the toolbar to add a custom node with associated context menu to the TaskResults control.
  9. Right-click the node and select Show Alert or Remove. Both are handled in the ItemClicked event on the ContextMenu.
  10. SimpleTask.aspx merely operated as a container for a custom task that associated context menus with results. Display the custom task dialog and enter a value to display in the TaskResults control. The results include the time on the server.
  11. Right-click the server time and select Show Alert or Remove. Both are handled in the custom task, in the ItemClicked event on the ContextMenu.

Common_ContextMenu_CSharp\SimpleMap.aspx Page contains a map with a ContextMenu.
Common_ContextMenu_CSharp\SimpleMap.aspx.cs Code behind.
Common_ContextMenu_CSharp\SimpleTask.aspx Page contains a map, a TaskResults control, and a custom task with a ContextMenu.
Common_ContextMenu_CSharp\SimpleTask.aspx.cs Code behind.
Common_ContextMenu_CSharp\SimpleTaskResults.aspx Page contains a map, and Toolbar, TaskResults, and ContextMenu controls.
Common_ContextMenu_CSharp\SimpleTaskResults.aspx.cs Code behind.
Common_ContextMenu_CSharp\SimpleToc.aspx Page contains a map and TOC. ContextMenus are configured on TOC contents.
Common_ContextMenu_CSharp\SimpleToc.aspx.cs Code behind.
Common_ContextMenu_CSharp\App_Code\SimpleTaskContextMenu_CSharp.cs Custom task that contains ContextMenus, adds them to results, and handles ContextMenu events.
Common_ContextMenu_CSharp\App_Code\Utility.cs Utility classes for the custom task.
Download the C# files
Common_ContextMenu_VBNet\SimpleMap.aspx Page contains a map with a ContextMenu.
Common_ContextMenu_VBNet\SimpleMap.aspx.vb Code behind.
Common_ContextMenu_VBNet\SimpleTask.aspx Page contains a map, a TaskResults control, and a custom task with a ContextMenu.
Common_ContextMenu_VBNet\SimpleTask.aspx.vb Code behind.
Common_ContextMenu_VBNet\SimpleTaskResults.aspx Page contains a map, and Toolbar, TaskResults, and ContextMenu controls.
Common_ContextMenu_VBNet\SimpleTaskResults.aspx.vb Code behind.
Common_ContextMenu_VBNet\SimpleToc.aspx Page contains a map and TOC. ContextMenus are configured on TOC contents.
Common_ContextMenu_VBNet\SimpleToc.aspx.vb Code behind.
Common_ContextMenu_VBNet\App_Code\SimpleTaskContextMenu_VBNet.vb Custom task that contains ContextMenus, adds them to results, and handles ContextMenu events.
Common_ContextMenu_VBNet\App_Code\Utility.vb Utility classes for the custom task.
Download the VB.NET files

Download the files for all languages