Common Select Buffer tool
Common_SelectBufferTool_VBNet\Default.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 System
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Partial Public Class [Default]
    Inherits System.Web.UI.Page
#Region "Instance Variable Declarations"

    Private _ADFCallbackFunctionString As String
    Private _callbackResults As String = ""


#End Region

#Region "ASP.NET Page Event Handlers"

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

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Make sure the page is not in a postback
        If (Not ScriptManager1.IsInAsyncPostBack) Then
            Try
                ' Get a reference to the Data Layers GIS Resource
                Dim commonMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality = Map1.GetFunctionality("Data Layers")
                Dim gisResource As ESRI.ArcGIS.ADF.Web.DataSources.IGISResource = commonMapFunctionality.Resource

                ' Get an object to query the resource
                Dim commonQueryFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality = CType(gisResource.CreateFunctionality(GetType(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), Nothing), ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)

                ' Use the query functionality to get the queryable layer names and ids from the resource
                Dim layerIDs() As String
                Dim layerNames() As String
                commonQueryFunctionality.GetQueryableLayers(Nothing, layerIDs, layerNames)

                ' Add the names of the queryable layers to the selection layer drop-down
                For i As Integer = 0 To layerNames.Length - 1
                    ddlSelectionLayer.Items.Add(layerNames(i))
                Next i
                ' Set the session variable storing the current selection layer to the first layer
                ' name in the selection layer drop-down
                Session("SelectionLayer") = ddlSelectionLayer.Items(0).Value

                Toc1.NodeSelectionUpdateControls.Add(ddlSelectionLayer.ClientID)
            Catch exception As System.Exception
                Dim jsAlertErrorMessage As String = String.Format("<script>{0}</script>", CustomComponents.Utility.GetJavaScriptErrorString(exception))
                Response.Write(jsAlertErrorMessage)
            End Try
        End If
    End Sub

#End Region

#Region "Instance Methods"

    Public Sub ClearSelection()
        Try
            ' Retrieve and clear the graphics of the Buffer and Selection resources.
            Dim gisFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality = Map1.GetFunctionality("Buffer")
            Dim graphicsMapResource As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource = TryCast(gisFunctionality.Resource, ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)
            graphicsMapResource.Graphics.Clear()
            Map1.RefreshResource(graphicsMapResource.Name)

            gisFunctionality = Map1.GetFunctionality("Selection")
            graphicsMapResource = TryCast(gisFunctionality.Resource, ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)
            graphicsMapResource.Graphics.Clear()
            Map1.RefreshResource(graphicsMapResource.Name)

            grdSelectionResults.Visible = False
            UpdatePanel1.Update()

            'chkSelectionInTable.Checked = false;

            Dim jsEnableCheckbox As String = String.Format("document.getElementById('{0}').checked = false", "chkSelectionInTable")
            Dim CheckboxCallbackResultselection As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript(jsEnableCheckbox)

            Map1.CallbackResults.Add(CheckboxCallbackResultselection)

            ' Set the callback results to those of the map.  These will be returned to the client and
            ' processed by processCallbackResult.
            _callbackResults = Map1.CallbackResults.ToString()
        Catch exception As System.Exception
            Dim errorCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = CustomComponents.Utility.GetErrorCallback(exception)
            Dim errorCallbackResultCollection As New ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection()
            errorCallbackResultCollection.Add(errorCallbackResult)
            _callbackResults = errorCallbackResultCollection.ToString()
        Finally
            ScriptManager1.RegisterDataItem(Page, _callbackResults.ToString(), False)
        End Try
    End Sub

#End Region

#Region "ASP.NET Web ADF Controls"
    Private Sub btnClearSelection_Click(ByVal sender As Object, ByVal e As EventArgs)
        ClearSelection()
    End Sub
#End Region
End Class