Common Context menu
Common_ContextMenu_VBNet\SimpleMap.aspx.vb
' Copyright 2010 ESRI
' 
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' 
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' 
' See the use restrictions.
' 

Imports Microsoft.VisualBasic
Imports System
Public Partial Class SimpleMap
  Inherits System.Web.UI.Page
  #Region "ASP.NET Page Life Cycle Event Handlers"

  Protected Sub Page_Init(ByVal sender As Object, ByVal eventArgs As System.EventArgs)
    ' Add an event handler for when an item is clicked on the context menu 
    AddHandler ContextMenu1.ItemClicked, AddressOf ContextMenu1_ItemClicked
  End Sub

  Protected Sub Page_PreRender(ByVal sender As Object, ByVal eventArgs As System.EventArgs)
    ' Make sure the event is not being fired as a result of a PostBack (i.e. is being fired as part of initial page load)
    If (Not IsPostBack) Then
      ' Make sure the context menu is clear of all items
      ContextMenu1.Items.Clear()

      ' Create a new context menu item and add it to the menu
      Dim zoomInContextMenuItem As ESRI.ArcGIS.ADF.Web.UI.WebControls.ContextMenuItem = New ESRI.ArcGIS.ADF.Web.UI.WebControls.ContextMenuItem()
      zoomInContextMenuItem.Text = "Zoom In"
      zoomInContextMenuItem.ImageUrl = "images/wrench.gif"
      ContextMenu1.Items.Add(zoomInContextMenuItem)

      ' Create a JavaScript call to a Web ADF function that shows a context menu.  We return false after making 
      ' the function call to prevent the default context menu from showing
      Dim showDataContextMenu As String = String.Format("esriShowContextMenu(event,'{0}','{1}','{2}');return false;", ContextMenu1.ClientID, Map1.UniqueID, "")

      ' Wire the JavaScript call to execute when the map control's oncontextmenu event is fired
      Map1.Attributes.Add("oncontextmenu", showDataContextMenu)
    End If
  End Sub

  #End Region

  #Region "Web ADF Control Event Handlers"

  Private Sub ContextMenu1_ItemClicked(ByVal sender As Object, ByVal contextMenuItemEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.ContextMenuItemEventArgs)
    ' Check the text of the context menu item clicked
    If contextMenuItemEventArgs.Item.Text = "Zoom In" Then
      ' Since the custom Zoom In menu item was clicked, call the map's Zoom function
      Map1.Zoom(2)
      ' Since the context menu initiated the callback, the context menu's callback results are processed
      ' when the callback returns to the client.  But since we executed Zoom on the map, it is that control
      ' that has callback results.  So to have the map's callback results processed on the client, we copy
      ' them to the context menu's callback results collection.
      ContextMenu1.CallbackResults.CopyFrom(Map1.CallbackResults)
    End If
  End Sub

  #End Region
End Class