Implementing a custom solution to manage callback content
This topic describes how to manage the callbackcontent when the Active Server Page (ASP) button's onClick event triggers an asynchronous callback to the server to change the 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.
Do the following steps to complete this task:
- Create a Web application using How to create a Web application with Web controls as a guide.
- In the Visual Studio toolbox, expand the standard tab and add two text box controls and a button control. Optionally, you can add labels for each text box. The interface appears as shown on the following screen shot:
- Open the Default.aspx in Source view and assign an id value of TextboxX to the first text box and an id value of TextboxY to the second text box. See the following code example:
<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>
- Since the button is initiating the partial postabck, it becomes important to register it with the ScriptManager for handling asynchronous postbacks. In the page_load event, add the code to register the button. See the following code example:
ScriptManager1.RegisterAsyncPostBackControl(Button1);
- 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 text boxes. 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. See the following code example:
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 text boxes,
// and with a width one quarter of 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 example. The string is passed to the client to render the contents. In this case, set the map's extent. See the following code example:
[HTML]
"[{\"id\":\"Map1\",\"type\":\"Map\",\"action\":\"setextent\",\"params\":[37.4464415417244,-125.74999094235874,82.5535584582756,-94.250009057641265]}]"
See Also:
ASP.NET AJAX partial postback solutionsHow 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