How to manage callback content for Web ADF control when partial postback is initiated by Non-Web ADF control


Summary This topic describes how to implement a custom solution to manage callback content—in this case, adding a Hypertext Markup Language (HTML) button to a Web page.

This topic is the second in a series of three related "How to" topics. The others are How to add a custom toolbar item to a toolbar control and How to use the Web ADF callback framework to interact with non-Web ADF content.

In this topic


Implementing a custom solution to manage callback content

This topic describes how to manage the callbackcontent when ASP button's onClick event triggers an asynchronous callback to the server to change map extent, retrieves the callback string from the Map control, and returns it to the client to trigger subsequent callbacks to update the map. You will add two ASP text boxes and a ASP button. The text boxes will receive an x and y coordinate for the map to center on. The button will trigger the action via an asynchronous callback to the server. The Web Application Developer Framework (ADF) JavaScript libraries will be used to process the callback response.
Perform the following steps to complete this task:
  1. Create a Web application using How to create a Web application with Web controls as a guide.
  2. In the Visual Studio toolbox, expand the standard tab and add two textbox controls and a button control. Optionally, you can add labels for each text box. The interface appears as follows:

  3. Open the Default.aspx in Source view and assign an id value of TextboxX to the first text box, an id value of TextboxY to the second text box.
[XML]
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="left: 404px;
position: absolute; top: 489px" TabIndex="3" Text="Zoom To Point" Width="122px" />
<asp:TextBox ID="TextBoxY" runat="server" Style="left: 265px; position: absolute;
top: 491px" TabIndex="2" Width="107px"></asp:TextBox>
<asp:TextBox ID="TextBoxX" runat="server" Style="left: 126px; position: absolute;
top: 492px" TabIndex="1" Width="95px"></asp:TextBox>
  1. Since the button is initiating the partial postabck, is becomes important to register it with ScriptManager for handling asynchronous postbacks. In the page_load event add the ode to register the button.
[C#]
ScriptManager1.RegisterAsyncPostBackControl(Button1);
  1. Add the click event for the button(Button1_Click) to retrieve the values from the text boxes. Perform calculations to calculate the extent based on the coordinate values in X and Y textboxes. Set the map's extent to the calculated extent and register the map's callback results as dataItem so they are processed on the client.
[C#]
protected void Button1_Click(object sender, System.EventArgs eventArgs)
{

    double xCenter = double.Parse(TextBoxX.Text);
    double yCenter = double.Parse(TextBoxY.Text);

    // Calculate 1/8 the width of the current map extent
    double adfMapWidthEighth = 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.
    ESRI.ArcGIS.ADF.Web.Geometry.Envelope adfNewExtentEnvelope = new
        ESRI.ArcGIS.ADF.Web.Geometry.Envelope(xCenter - adfMapWidthEighth, yCenter -
        adfMapWidthEighth, xCenter + adfMapWidthEighth, yCenter + adfMapWidthEighth);

    Map1.Extent = adfNewExtentEnvelope;

    ScriptManager1.RegisterDataItem(Page, Map1.CallbackResults.ToString(), false);
}
When the Button1_click method completes, the mapstring variable will contain a Web ADF specific string as shown in the following code. The string is passed to the client to render the contents , in this case set the map's extent.
[HTML]
"[{\"id\":\"Map1\",\"type\":\"Map\",\"action\":\"setextent\",\"params\":[37.4464415417244,-125.74999094235874,82.5535584582756,-94.250009057641265]}]"


See Also:

ASP.NET AJAX partial postback solutions
How to add a custom tool and manage callback results from Web ADF Controls
How to use Web ADF partial postback solution to interact with non-Web ADF content and manage the callback results