Home arrow GIS Data & Resources arrow Scripts and Code arrow C# Code arrow Getting the Value of an asp Control From Within an IMapServerToolAction Class
Getting the Value of an asp Control From Within an IMapServerToolAction Class PDF Print E-mail

Written by Barry Biediger,

The solution to this problem might seem obvious to .NET pros, but it took a bit of digging around for me to figure this one out.
   
Below is a class that handles events from a tool that allows the user to draw a polygon on the map. Since it is in the file "ToolbarActions.cs" it can't  directly reference an asp control by its ID from the Default.aspx page, in this case "chkDrawPolygon", like it could if the asp control was a local variable. In this case if the checkbox is checked the polygon will be added to the graphics layer and displayed to the user.

The simple solution to this problem is to get a reference to the Page, which has a method that will find a control based on it's name. args.Control refers to the Map from which we can get the Page object. This is a much more elegant solution than dealing with Session variables and the like.
   
    public class DrawPolygonTool : IMapServerToolAction
    {
        public void ServerAction(ToolEventArgs args)
        {
            PolygonEventArgs events = args as PolygonEventArgs;
            ESRI.ArcGIS.ADF.Web.Geometry.Polygon polygon = AGRC.Utilities.Geometry.CreatePolygonFromPolygon(events);
            System.Web.UI.WebControls.CheckBox chkDrawPolygon = args.Control.Page.FindControl("chkDrawPolygon") as System.Web.UI.WebControls.CheckBox;
          

            if (chkDrawPolygon.Checked = true)
            {
                System.Drawing.Color color = System.Drawing.Color.White;
                
                //send the polygon, color and transparency to a method that will draw it on the graphics layer//
                AGRC.Utilities.Functionality.AddGeometryToGraphics(polygon as ESRI.ArcGIS.ADF.Web.Geometry.Geometry, color, 50);
            }

        }
    }


Users' Comments  
 

No comment posted

Add your comment

28, Aug. 2008
Last Updated ( 28, Aug. 2008 )
 
< Prev   Next >

AGRC Contacts | UGIC Contacts

feed image feed image

Utah GIS Portal © 2009 AGRC

Optimized for