Common Callback


Purpose
This sample demonstrates how to utilize asynchronous callbacks with the Web Application Developer Framework (ADF) controls. The Web ADF provides event handling and standard interface server-side controls, such as a Map and Toolbar, as well as a complete set of JavaScript libraries to initiate and process callbacks on the client. The Web ADF is callback enabled by default. However, custom asynchronous callback solutions can be developed to initiate changes in map display and to update other non-Web ADF components on a page.
 
This sample provides the following examples:
  • A custom tool in a toolbar to center the map on a user click—Custom CallbackResult objects are created to change the extent labels on the edges of the map. The CallbackResult objects are added to the Map control's CallbackResults collection and processed by Web ADF client-side JavaScript.
  • A custom Hypertext Markup Language (HTML) client-side button to initiate a callback, which centers and zooms in on a user entered point—The Page implements the ICallbackEventHandler interface to handle the callback request (RaiseCallbackEvent()) and send the callback response (GetCallbackResult()). The callback response is handled by the Web ADF JavaScript libraries.
  • A custom ASP.NET Menu control with manually added menu items that enables the user to zoom to an extent—The Page handles the callback request and response for the zoom to extent items.

How to use

If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

At design time
  1. Verify that the Web ADF for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
  2. In Windows Explorer, navigate to <ArcGIS install location>\DeveloperKit10.0\Samples\ServerNET. This folder contains the Common_Callback CSharp and VBNet folders.
  3. Open the folder of the language you're going to use—CSharp or VBNet—and copy the Common_Callback_<language> folder to c:\inetpub\wwwroot. The <language> variable can be either CSharp or VBNet.
  4. Open the IIS Manager from Control Panel > Administrative Tools > Internet Information Services (IIS) Manager or Internet Information Services.
  5. In the console tree view on the left, navigate to Local Computer > Web Sites > Default Web Site, expand Default Web Site, right-click the Common_Callback_<language> folder, and click Properties. The Properties dialog box opens.
  6. Click the Directory tab, click the Create button in the Application Settings section, then click OK to close the Properties dialog box.
  7. Start Microsoft Visual Studio 2008 or 2010 and open the Common_Callback_<language> solution (for example, Common_Callback_CSharp2008.sln) located in c:\inetpub\wwwroot\Common_Callback_<language>\Common_Callback_<language><vs_version>. The <vs_version> references the Visual Studio version of the solution, e.g. either 2008 or 2010.
  8. In Solution Explorer, right-click Default.aspx and select Set As Start Page.
  9. Open the Default.aspx page in Design view, open the properties window for the MapResourceManager control, and click the ellipsis next to the ResourceItems property. The ResourceItem Collection Editor dialog box opens.
  10. Add or change the MapResourceItem associated with a map service (ArcGIS Server, ArcIMS and so on). In some of the sample code, it is assumed that the resource is in a geographic coordinate system.
  11. If necessary, set the run time identity of the Web application by following one of the following two steps. If not necessary, proceed to step 14.
  12. At design time, the identity of the user running Visual Studio is used to connect to an ArcGIS Server local data source. At run time, that identity is established by the Web application. Only one identity can be used to define access to the ArcGIS Server local data sources in a single Web application. This identity can be explicitly defined when building the Web ADF application in Visual Studio by right-clicking the Web project in Solution Explorer and selecting the Add ArcGIS Identity option. Enter the identity credentials that will be used to access ArcGIS Server local resources at run time. This information is added to the web.config file in a standard ASP.NET identity tag. If the Encrypt identity in web.config check box is checked, the identity tag will be encrypted; otherwise, the username and password are stored as clear text.
  13. Open the web.config file, add an <identity> element in <system.web>, set the impersonate attribute to true, and add a username and password attribute and set them to a valid user account. If you're working with ArcGIS Server local data sources, ensure the account has access to the geographic information system (GIS) server resources referenced in the Map control.
  14. Save the project.
  15. Click the Debug drop-down menu and click Start Debugging.

At run time
  1. Browse to the viewer uniform resource locator (URL) (for example, http://localhost/Common_Callback_CSharp).
  2. On the toolbar above the map, click the Zoom In tool, and zoom in to an area of the map. The HTML text on the edges of the map control the update with the extent boundaries of the map. This information was appended to the callback for the Map control upon an extent change. The Web ADF JavaScript libraries processed the custom CallbackResult objects and updated the appropriate content.
  3. On the toolbar above the map, click the CenterAt Tool.
  4. Click an area of the map. The map redraws centered on the location clicked. The custom tool code shows that the Map control was not explicitly refreshed. If the content of the map does not change and the scale remains the same, the map does not need to call Refresh(). The custom tool also includes code to create custom CallbackResult objects to modify other content on the page. This is provided as an example of how to do this in a custom tool.
  5. Below the map, enter x and y coordinates in the text boxes provided.
  6. Click the Zoom To Point button to zoom to the coordinates provided. This initiates a custom callback to the Web application. A string message containing the type of action and the coordinate values is sent to the Web application via the ZoomToPointClient() JavaScript function in the Default.aspx file. The ZoomToPointServer() method in the page code file (for example, Default.aspx.cs) processes the request and applies changes to the map. The map is refreshed on the client without requiring a full postback.
  7. In the custom menu to the upper right of the map, select the option to zoom to a defined location: California or New York. In both locations, it is assumed that the map is in a geographic coordinate system. You can change the code in the page code file to modify this behavior.

Common_Callback_CSharp\Default.aspx User interface for the Web application.
Common_Callback_CSharp\Default.aspx.cs Code behind the user interface.
Common_Callback_CSharp\App_Code\CustomTool.cs Class library containing the implementation of a custom tool.
Download the C# files
Common_Callback_VBNet\Default.aspx User interface for the Web application.
Common_Callback_VBNet\Default.aspx.vb Code behind the user interface.
Common_Callback_VBNet\App_Code\CustomTool.vb Class library containing the implementation of a custom tool.
Download the VB.NET files

Download the files for all languages