Common_SelectBufferTool_CSharp\Default.aspx.cs
// 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. // using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default : System.Web.UI.Page { #region Instance Variable Declarations private string _ADFCallbackFunctionString; private string _callbackResults = ""; #endregion #region ASP.NET Page Event Handlers protected void Page_Load(object sender, System.EventArgs e) { ScriptManager1.RegisterAsyncPostBackControl(btnClearSelection); ScriptManager1.RegisterAsyncPostBackControl(chkSelectionInTable); btnClearSelection.Click += new EventHandler(btnClearSelection_Click); } protected void Page_PreRender(object sender, System.EventArgs e) { // Make sure the page is not in a postback if (!ScriptManager1.IsInAsyncPostBack) { try { // Get a reference to the Data Layers GIS Resource ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality commonMapFunctionality = Map1.GetFunctionality("Data Layers"); ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisResource = commonMapFunctionality.Resource; // Get an object to query the resource ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality commonQueryFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisResource.CreateFunctionality( typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null); // Use the query functionality to get the queryable layer names and ids from the resource string[] layerIDs; string[] layerNames; commonQueryFunctionality.GetQueryableLayers(null, out layerIDs, out layerNames); // Add the names of the queryable layers to the selection layer drop-down for (int i = 0; i < layerNames.Length; i++) { ddlSelectionLayer.Items.Add(layerNames[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 (System.Exception exception) { string jsAlertErrorMessage = string.Format("<script>{0}</script>", CustomComponents.Utility.GetJavaScriptErrorString(exception)); Response.Write(jsAlertErrorMessage); } } } #endregion #region Instance Methods public void ClearSelection() { try { // Retrieve and clear the graphics of the Buffer and Selection resources. ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality gisFunctionality = Map1.GetFunctionality("Buffer"); ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource graphicsMapResource = gisFunctionality.Resource as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource; graphicsMapResource.Graphics.Clear(); Map1.RefreshResource(graphicsMapResource.Name); gisFunctionality = Map1.GetFunctionality("Selection"); graphicsMapResource = gisFunctionality.Resource as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource; graphicsMapResource.Graphics.Clear(); Map1.RefreshResource(graphicsMapResource.Name); //Hide the grid grdSelectionResults.Visible = false; UpdatePanel1.Update(); //Disable the checkbox for displaying selection string jsEnableCheckbox = string.Format("document.getElementById('{0}').checked = false", "chkSelectionInTable"); ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult CheckboxCallbackResultselection = 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 (System.Exception exception) { ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult errorCallbackResult = CustomComponents.Utility.GetErrorCallback(exception); ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection errorCallbackResultCollection = new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection(); errorCallbackResultCollection.Add(errorCallbackResult); _callbackResults = errorCallbackResultCollection.ToString(); } finally { ScriptManager1.RegisterDataItem(Page, _callbackResults.ToString(), false); } } #endregion #region ASP.NET Web ADF Controls void btnClearSelection_Click(object sender, EventArgs e) { ClearSelection(); } #endregion }