Common_CustomTasks_VBNet\CustomTasksWebSite\QueryBuilderTaskWebPage.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. ' Partial Public Class QueryBuilderTaskWebPage Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) ScriptManager1.RegisterAsyncPostBackControl(SwitchMapsButton) End Sub Protected Sub Page_PreRender(ByVal sender As Object, ByVal eventArgs As System.EventArgs) Dim scriptKeyCustom As String = "customDataItemScript" ' Check whether the data items processing script needs to be registered If (Not Me.Page.ClientScript.IsClientScriptBlockRegistered(Me.GetType(), scriptKeyCustom)) AndAlso (Not ScriptManager1.IsInAsyncPostBack) Then ' Construct the JavaScript block that will be responsible for processing data items. Dim scriptBlock As String = "" & ControlChars.CrLf & " " & ControlChars.CrLf & " function onLoadFunction(){{" & ControlChars.CrLf & " Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(AsyncResponseHandler);" & ControlChars.CrLf & " }}" & ControlChars.CrLf & ControlChars.CrLf & " function AsyncResponseHandler(sender, args) {{" & ControlChars.CrLf & " var dataItems = args.get_dataItems();" & ControlChars.CrLf & " if (dataItems['{0}'] != null)" & ControlChars.CrLf & " ESRI.ADF.System.processCallbackResult(dataItems['{0}']);" & ControlChars.CrLf & " }}" & ControlChars.CrLf & ControlChars.CrLf & " Sys.Application.add_init(onLoadFunction);" ' Insert the client ID of the page into the script block. scriptBlock = String.Format(scriptBlock, Page.ClientID) ' Register the script on the client. Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), scriptKeyCustom, scriptBlock, True) End If End Sub Protected Sub SwitchMapsButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' Switch the map referenced by the TaskResults and QueryBuilderTask If TaskResults1.Map = Map1.ID Then TaskResults1.Map = Map2.ID QueryBuilderTask1.Map = Map2.ID Else TaskResults1.Map = Map1.ID QueryBuilderTask1.Map = Map1.ID End If ' Get any task results stored in session Dim savedTaskResultsArray() As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode = TryCast(Session("TaskResultsNodes"), ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode()) ' Store the task results of the current map in session Dim currentTaskResultArray(TaskResults1.Nodes.Count - 1) As ESRI.ArcGIS.ADF.Web.UI.WebControls.TreeViewPlusNode TaskResults1.Nodes.CopyTo(currentTaskResultArray) Session("TaskResultsNodes") = currentTaskResultArray ' Clear task results TaskResults1.Nodes.Clear() ' Add saved task results If savedTaskResultsArray IsNot Nothing Then For i As Integer = 0 To savedTaskResultsArray.Length - 1 TaskResults1.Nodes.Add(savedTaskResultsArray(i)) Next i End If ' Refresh the task results control to show updates TaskResults1.Refresh() ' Construct JavaScript call to update the QueryBuilderTask Dim jsUpdateQueryBuilderTask As String = String.Format("var task = $find('{0}'); task.getLayers();", QueryBuilderTask1.ClientID) Dim updateQueryBuilderCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateJavaScript(jsUpdateQueryBuilderTask) ' Place callback results in one collection Dim callbackResults As New ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResultCollection() callbackResults.CopyFrom(TaskResults1.CallbackResults) callbackResults.Add(updateQueryBuilderCallbackResult) ' Register callback results as a data item so they are processed on the client ScriptManager1.RegisterDataItem(Page, callbackResults.ToString(), False) End Sub End Class