English

How To: Set initial extent for .NET Web application

Summary

At design time, the InitialExtent property of a map control can be set to default or full.

Default uses the extent of the primary map resource. Full uses an extent that includes all resources in the map. To explicitly set the extent of the map control upon application initialization, add the appropriate code to the PreRender event of the page or map. The following procedure uses a custom Web ADF envelope to define the initial extent of the map.

Note:
The initial extent only needs to be set on the initial request to the application, not on every subsequent postback.

Procedure

1. Go to C:\Inetpub\wwwroot\<your Web site> folder. Open Default.aspx.cs file in Notepad.

2. Copy the following code into any two 'protected void' sessions and change the extent to the desired extent values:

Code:
protected void Page_PreRender(object sender, EventArgs ea){
if (!Page.IsPostBack){
ESRI.ArcGIS.ADF.Web.Geometry.Envelope initextent = new

ESRI.ArcGIS.ADF.Web.Geometry.Envelope(-110, 30,-100, 40);
Map1.Extent = initextent;
}
}


3. Save the file and refresh the Web site.