Common Partial Postback
Common_PartialPostback_VBNet\RegisterScriptBlockDemo.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 RegisterScriptBlockDemo
  Inherits System.Web.UI.Page
  #Region "ASP.NET Page Life Cycle Event Handlers"

  Protected Sub Page_Load(ByVal sender As Object, ByVal eventArgs As System.EventArgs)
    ' Register the Zoom To Point button and Zoom To Menu to issue postbacks asynchronously.  Note that
    ' controls registered in this way must implement either INamingContainer, IPostBackDataHandler, or 
    ' IPostBackEventHandler
    ScriptManager1.RegisterAsyncPostBackControl(Button1)
    ScriptManager1.RegisterAsyncPostBackControl(Menu1)
  End Sub

  #End Region

  #Region "ASP.NET WebControl Event Handlers"

  ' Fires when the Zoom To Point button is clicked
  Protected Sub Button1_Click(ByVal sender As Object, ByVal eventArgs As System.EventArgs)
    ' Get the values from the X and Y textboxes
    Dim xCenter As Double = Double.Parse(TextBoxX.Text)
    Dim yCenter As Double = Double.Parse(TextBoxY.Text)

    ' Calculate 1/8 the width of the current map extent
    Dim adfMapWidthEighth As Double = Map1.Extent.Width / 8

    ' Create an envelope with its center at the coordinates specified in the X and Y textboxes,
    ' and with a width one quarter that of the current map extent.
    Dim adfNewExtentEnvelope As ESRI.ArcGIS.ADF.Web.Geometry.Envelope = New ESRI.ArcGIS.ADF.Web.Geometry.Envelope(xCenter - adfMapWidthEighth, yCenter - adfMapWidthEighth, xCenter + adfMapWidthEighth, yCenter + adfMapWidthEighth)

    ' Update the map extent to the new envelope
    Map1.Extent = adfNewExtentEnvelope

    ' Construct the JavaScript necessary to perform client-side processing of the callback 
    ' results generated from manipulating the map.  Note that we need to modify the escape 
    ' sequencing on the default callback results string for the script to execute properly, 
    ' hence the call to Replace on the Map's callback results string.
        Dim jsProcessCallbackResult As String = String.Format("ESRI.ADF.System.processCallbackResult('{0}');", Map1.CallbackResults.ToString().Replace("\", "\\"))
    ' Register the call to processCallbackResult as a script on the client.
    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, sender.GetType(), "changeextent", jsProcessCallbackResult, True)
  End Sub

  ' Fires when an item on the Zoom To menu is clicked
  Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal menuEventArgs As System.Web.UI.WebControls.MenuEventArgs)
    ' Declare and initialize variables to store the bounds of the new map extent
    Dim minX As Double = 0
    Dim minY As Double = 0
    Dim maxX As Double = 0
    Dim maxY As Double = 0

    ' Check the passed-in location and initialize the extent parameters accordingly
    Select Case menuEventArgs.Item.Text
      Case "California"
        minX = -128.0
        minY = 31.0
        maxX = -111.0
        maxY = 43.0
      Case "New York"
        minX = -80.0
        minY = 40.5
        maxX = -73.0
        maxY = 45.5
      Case "Kansas"
        minX = -103.0
        minY = 35.0
        maxX = -93.0
        maxY = 42.0
      Case Else
    End Select
    ' Create a Web ADF envelope with the new extent parameters
    Dim adfNewExtentEnvelope As ESRI.ArcGIS.ADF.Web.Geometry.Envelope = New ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minX, minY, maxX, maxY)

    ' Update the map control's extent with the newly created envelope
    Map1.Extent = adfNewExtentEnvelope

    ' Construct the JavaScript necessary to perform client-side processing of the callback 
    ' results generated from manipulating the map.  Note that we need to modify the escape 
    ' sequencing on the default callback results string for the script to execute properly, 
    ' hence the call to Replace on the Map's callback results string.
        Dim jsProcessCallbackResult As String = String.Format("ESRI.ADF.System.processCallbackResult('{0}');", Map1.CallbackResults.ToString().Replace("\", "\\"))
    ' Register the call to processCallbackResult as a script on the client.
    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, sender.GetType(), "changeextent", jsProcessCallbackResult, True)
  End Sub

  #End Region

  #Region "Web ADF Control Event Handlers"

  ' Fires whenever the map's extent changes
  Protected Sub Map1_ExtentChanged(ByVal sender As Object, ByVal extentEventArgs As ESRI.ArcGIS.ADF.Web.UI.WebControls.ExtentEventArgs)
    ' New extent is the explicit envelope the Map extent will be set to.  Note that the aspect ratio of the map 
    ' extent has been adjusted to account for pixel image size / extent size discrepancies. 
    Dim adfEnvelope As ESRI.ArcGIS.ADF.Web.Geometry.Envelope = extentEventArgs.NewExtent

    ' Update extent boundary label values.  Note that we have to update the values on both the server (via
    ' Label.Text) and the client (via CreateSetInnerContent callback results).  The update on the server
    ' makes it so that the value persists across postbacks that don't fire the ExtentChanged event.  The
    ' update on the client makes it so that the change is actually shown on the client.

    ' Set label text on the server
    LabelN.Text = adfEnvelope.YMax.ToString("N")
    LabelE.Text = adfEnvelope.XMax.ToString("N")
    LabelS.Text = adfEnvelope.YMin.ToString("N")
    LabelW.Text = adfEnvelope.XMin.ToString("N")

    ' Update label text on the client via the map control's callback results.  Since the event was fired by the
    ' map control, the map's callback results - including any we choose to add - are processed on the client without
    ' any further action (such as registering a script block or data item).
    Dim updateLabelCallbackResult As ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateSetInnerContent(LabelN, adfEnvelope.YMax.ToString("N"))
    Map1.CallbackResults.Add(updateLabelCallbackResult)
    updateLabelCallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateSetInnerContent(LabelE, adfEnvelope.XMax.ToString("N"))
    Map1.CallbackResults.Add(updateLabelCallbackResult)
    updateLabelCallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateSetInnerContent(LabelS, adfEnvelope.YMin.ToString("N"))
    Map1.CallbackResults.Add(updateLabelCallbackResult)
    updateLabelCallbackResult = ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult.CreateSetInnerContent(LabelW, adfEnvelope.XMin.ToString("N"))
    Map1.CallbackResults.Add(updateLabelCallbackResult)
  End Sub

  #End Region
End Class