Common_TaskResults_VBNet\TaskResultsWebSite\SelectionSet.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 SelectionSet Inherits System.Web.UI.Page #Region "Toc Control Event Handlers - NodesPopulated, NodeSelected" ' Fires after the TOC nodes have been initialized. Makes layer nodes selectable. Protected Sub Toc1_NodesPopulated(ByVal sender As Object, ByVal e As System.EventArgs) For Each node As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode In Toc1.Nodes Me.MakeLayerNodesSelectable(node) Next node End Sub ' Fires when a TOC node is selected. Updates the active layer ID and resource name session variables and the ' selection layer display in the browser's status bar. Protected Sub Toc1_NodeSelected(ByVal sender As Object, ByVal args As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNodeEventArgs) ' Make sure the node is a layer node If Not(TypeOf args.Node.Data Is ESRI.ArcGIS.ADF.Web.TocLayer) Then Return End If ' Update the layer ID session variable Dim tocLayer As ESRI.ArcGIS.ADF.Web.TocLayer = TryCast(args.Node.Data, ESRI.ArcGIS.ADF.Web.TocLayer) Me.Session("ActiveLayerID") = tocLayer.ID ' Get the data frame node containing the layer and use it to update the resource name session variable Dim dataFrameNode As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode = Me.GetParentDataFrameNode(TryCast(args.Node.Parent, ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode)) Me.Session("ActiveResourceName") = dataFrameNode.Text ' Construct JavaScript to display the name of the active layer in the browser's status bar Dim statusBarUpdateScript As String = String.Format("window.status = 'Selection Layer: {0}'", args.Node.Text) ' Embed the script in a callback result and add it to the TOC's collection so it is executed on the client Toc1.CallbackResults.Add(ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript(statusBarUpdateScript)) End Sub #End Region #Region "Private Instance Methods" ' Finds TOC layer nodes that are descendants of the passed-in node and makes them selectable Private Sub MakeLayerNodesSelectable(ByVal node As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode) ' Check whether the passed-in node is a layer node and make it selectable if so If TypeOf node.Data Is ESRI.ArcGIS.ADF.Web.TocLayer Then node.ClickBehavior = ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNodeClickBehavior.Selectable End If ' Recursively call the method on the passed-in node's child nodes For Each childNode As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode In node.Nodes Me.MakeLayerNodesSelectable(childNode) Next childNode End Sub ' Retrieves the TOC data frame node that is an ancestor of the passed-in node Private Function GetParentDataFrameNode(ByVal node As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode) As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode ' Declare a node variable to hold the function's return value Dim dataFrameNode As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode = Nothing ' If the current node is a data frame node, store it in the return variable. Otherwise, call the ' method recursively on the node's parent. If TypeOf node.Data Is ESRI.ArcGIS.ADF.Web.TocDataFrame Then dataFrameNode = node Else dataFrameNode = Me.GetParentDataFrameNode(TryCast(node.Parent, ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode)) End If Return dataFrameNode End Function #End Region End Class