ArcGIS Select Buffer tool
ArcGIS_SelectBufferTool_VBNet\Default.aspx.vb
' Copyright 2011 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 _Default
  Inherits System.Web.UI.Page


    Private _callbackResultCollection As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection = New ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection()
    Private m_targetResourceName As String = "MapResourceItem0"

    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        ScriptManager1.RegisterAsyncPostBackControl(ClearAllButton)
        AddHandler ClearAllButton.Click, AddressOf ClearAllButton_Click
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            ' Initialize the target resource name session variable only if the page request is at the beginning
            ' of a session
            If Session.IsNewSession Then
                Session("targetResourceName") = m_targetResourceName
            End If

            ' Make sure the page is not being rendered during a postback (i.e. is rendering during initial page
            ' load or on page refresh)
            If (Not IsPostBack) Then
                ' Create a query functionality object to use for retrieving the target resource's queryable layers
                Dim commonMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality = CType(Map1.GetFunctionality(m_targetResourceName), ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)
                Dim gisResource As ESRI.ArcGIS.ADF.Web.DataSources.IGISResource = commonMapFunctionality.Resource
                Dim queryFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality = CType(gisResource.CreateFunctionality(GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), Nothing), ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)

                ' Retrieve the queryable layers
                Dim layerIDs As String() = Nothing
                Dim layerNames As String() = Nothing
                queryFunctionality.GetQueryableLayers(Nothing, layerIDs, layerNames)

                ' Add the queryable layers to the active layer drop-down list
                Dim i As Integer = 0
                Do While i < layerNames.Length
                    activeLayerDropDownList.Items.Add(layerNames(i))
                    i += 1
                Loop

                ' Add all the ArcGIS Server unit types to the units drop-down list except for unknown, points, 
                ' and decimal degress
                Dim agsUnitTypes As System.Array = System.Enum.GetValues(GetType(ESRI.ArcGIS.ADF.Web.DataSources.Units))
                For Each agsUnitType As Integer In agsUnitTypes
                    Dim unit As String = agsUnitTypes.GetValue(agsUnitType).ToString()
                    If (unit <> "Unknown") AndAlso (unit <> "DecimalDegrees") AndAlso (unit <> "Points") Then
                        unitsDropDownList.Items.Add(unit)
                    End If
                Next agsUnitType
            End If
        Catch exception As System.Exception
            Dim jsErrorAlertString As String = String.Format("<script>{0}</script>", Utility.GetJavaScriptErrorString(exception))
            Response.Write(jsErrorAlertString)
        End Try
    End Sub

    ' Clears all selected features and removes all graphics from the target resource
    Private Sub ClearGraphicsAndSelection()
        ' Get the map functionality of the target resource
        Dim agsMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality = TryCast(Map1.GetFunctionality(m_targetResourceName), ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)

        ' Get the map description of the target resource and clear all graphics from it
        Dim agsSoapMapDescription As ESRI.ArcGIS.ADF.ArcGISServer.MapDescription = agsMapFunctionality.MapDescription
        agsSoapMapDescription.CustomGraphics = Nothing

        ' Iterate through each layer's layer description and clear all selected features
        ' from each
        Dim agsSoapLayerDescriptionArray As ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription() = agsSoapMapDescription.LayerDescriptions
        For Each agsSoapLayerDescription As ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription In agsSoapLayerDescriptionArray
            agsSoapLayerDescription.SelectionFeatures = Nothing
        Next agsSoapLayerDescription

        ' Refresh the target resource so the changes are displayed
        Map1.RefreshResource(m_targetResourceName)
        _callbackResultCollection.CopyFrom(Map1.CallbackResults)
        ScriptManager1.RegisterDataItem(Page, _callbackResultCollection.ToString(), False)
    End Sub

    Private Sub ClearAllButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        ClearGraphicsAndSelection()
    End Sub


End Class