Common Custom controls


Purpose
This sample discusses the custom controls—ADFCompositeControl, ADFWebPart, and CustomControlsWeb—with examples of their use in a Web application. For more details, see the "Additional information" section in this sample.
Note: Local (DCOM) connections are only supported for ArcGIS for Server versions prior to 10.1.

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 Application Developer Framework (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 Developer Kit install location>\Samples\ServerNET\Common_CustomControls.
  3. Start Visual Studio 2010 and open the Common_CustomControls_<language><vs_version> solution (for example, Common_CustomControls_CSharp2010.sln) located in <unzipped location\CustomControls_<language>. The <vs_version> references the Visual Studio version of the solution.
  4. In the Solution Explorer, right-click the CustomControlsWeb file system Web site and select Set as StartUp Project.
  5. Right-click the .aspx page that you are interested in and select Set As Start Page.
  6. Add the ADFCompositeControl and ADFWebPart projects as references to the CustomControlsWebSite if necessary.
  7. Open AddWebPartOnClick.aspx.cs and set the appropriate properties for MapWebPart and MapGridViewWebPart as follows: Define the data source type, location, and resource (map service) name for MapWebPart. The custom MapIdentify code and tool in MapWebPart will execute successfully but will not generate results. They are provided for instruction only. If necessary, add functionality to the tool. Default properties are set in the constructor for MapWebPart and MapGridViewWebPart, and use sample data provided by serverapps.esri.com and ArcGIS Online. To use the default properties, proceed to Step 10. To change the properties of MapWebPart, proceed to Step 8. To change the properties of MapGridViewWebPart, proceed to Step 9.
  8. Define the data source type, location, and resource (map service) name. The custom MapIdentify code and tool in MapWebPart will execute successfully but will not generate results. They are provided for instruction only. If necessary, add functionality to the tool.
  9. Define the data source type, location, and resource name for an ArcGIS for Server non-cached map service. Ensure the map service contains a point feature layer to be used to display graphics in the map and attributes in the GridView. Set the DataLayerName property to the name of the point feature layer. To filter and alias the field names in the point feature layer, which will be listed in the GridView, define a fields collection and set the DisplayFields property. MapGridViewWebPart contains a map resource that references the ArcGIS Online StreetMap service as a base layer. The non-cached map service is projected on-the-fly to the projection of the StreetMap service. A Geometry service is also used to project the default extent of the non-cached map service into the projection of the StreetMap service, and is then used to set the extent of the Map control. Set the GeometryServiceUrl property to an available ArcGIS for Server Geometry service.
  10. Open DesignComposite.aspx and set the appropriate properties on the MapToolTocControl in the markup. Define the data source type, location, and resource (map service) name. The custom MapIdentify code and tool in the MapToolTocControl will execute successfully but will not generate results. They are provided for instruction only. If necessary, add functionality to the tool.
  11. Open WebUserControl.ascx in Design view and add a map resource. The code behind the user control contains a block of code to set buddy properties at the initialization phase of the control.
  12. In Windows Explorer, navigate to the App_Data\Personalization_Data folder in CustomControlsWeb. Open the properties on the folder and provide read and write access to the user account under which the Web application will be running. If running as a file system Web site, integrated authentication is used by default.

At run time
  1. Start the Web application. Since it is a file system Web site, an ASP.NET Development server will start or an existing server instance will be used. Access to the site is limited to the local machine.
  2. In AddWebPartOnClick.aspx, click the Add MapWebPart or MapGridViewWebPart button. The respective Web Part control is added to the page. Multiple controls can be added in the same session. The MapWebPart control provides an interactive Map, Toolbar, and Toc control. The MapGridViewWebPart control provides an interactive Map, GridView, and point graphic features in the Map (MapTips). The GridView contains attributes for the point features displayed in the Map. On hover of a data row, the respective point graphic feature in the map is highlighted. On click of a data row, the Map zooms to the respective graphic feature. Only graphic features in the Map extent are listed in the GridView. Click the Remove Web Parts button to remove all parts from the page. A text file containing encrypted data is generated in the App_Data\Personalization_Data folder. The text is used to store the authenticated user's personalized information.
  3. Optionally, interact with the Map, TOC, and Toolbar control in the custom composite control on the DesignComposite.aspx page. This page illustrates that the Web ADF controls function as expected when contained in a composite control.
  4. Optionally, interact with the Map, TOC, and Toolbar control in the custom Web user control on the DesignTimeUserControl.aspx page. This page illustrates that the Web ADF controls function as expected in a user control.

Additional information

  • ADFCompositeControl project—Contains a custom composite server control. The server control contains Web ADF controls—Map, MapResourceManager, Toolbar, and Toc—that are created and configured during the life cycle of the control and the page in which it resides. This control provides a basic pattern for utilizing Web ADF controls in a custom server control.
  • ADFWebPart project—Contains custom composite server controls as ASP.NET Web Parts. ASP.NET Web Parts can be deployed with Microsoft Office SharePoint Server and personalized by end users.
    • MapGridViewWebPart—Contains a Web ADF Map and an ASP.NET GridView in an UpdatePanel, and requires that a ScriptManager be on the page. On initial load, the map shows a set of customers in downtown San Francisco. The GridView shows only those customers in the current map extent. On hover over a row in the GridView, the respective customer is highlighted in the map. On click of a row in the GridView, the map re-centers on the customer (graphic point) associated with the clicked row. All interaction rows in the GridView are managed on the client using the Web ADF JavaScript Library.
    • MapWebPart—Provides a simple ASP.NET Web Part example with a Map, MapResourceManager, Toolbar, and Toc control. The default personalization provider for ASP.NET is Structured Query Language (SQL) Express. If you do not have SQL Express installed, a personalization store is not created (on initial execution of the application), and an error is returned when attempting to add the custom Web Part to the page at run time. To alleviate this requirement, a custom personalization provider that uses text files has been added (TextFilePersonalizationProvider) to the demo Web site. For the code, markup, and discussion for this technique, see the Microsoft Developer Network (MSDN) Web site topic, Web Parts Personalization Providers.
    To deploy these Web Parts in SharePoint, use the ADF_AJAX_SharePoint_deployment_ReadMe.doc Word document (packaged with the sample) as a guide. A SharePoint 2007 server might not have session state enabled, which is necessary for Web ADF controls to function. If not enabled, SharePoint returns an uninformative error when attempting to add a custom Web Part that contains ADF controls to the SharePoint server. See Step 5 in the Word document for more information.
  • CustomControlsWeb—Contains pages that demonstrate the use of the composite server control and Web Part controls. AddWebPartOnClick.aspx illustrates how to add and remove Web Parts at run time. This page can be used to test the run time use of a Web Part in SharePoint.

    DesignComposite.aspx illustrates how a custom composite server control can be added and configured at design time. This Web site also contains a custom Web user control (WebUserControl). The user control contains a Map, MapResourceManager, Toolbar, and Toc control. The code behind the user control configures the buddy relationships that need to be established when the user control is initialized. DesignTimeUserControl.aspx illustrates how the custom user control is used in a page at design time.

    CustomControlsWeb is a file system Web site because integrated authentication is used by the ASP.NET development server to determine an authenticated user. The text file-based personalization provider requires an authenticated user to function. By default, IIS Web applications are configured with anonymous access enabled, so no authenticated user is provided. To use with IIS, disable anonymous access to the Web application.


CustomControls_CSharp\ADFCompositeControl\Properties\AssemblyInfo.cs Assembly information for ADFCompositeControl.
CustomControls_CSharp\ADFCompositeControl\MapToolTocControl.cs ADFCompositeControl implementation code. Contains a MapResourceManager, Map, Toolbar, and Toc control.
CustomControls_CSharp\ADFCompositeControl\MapIdentify.cs Custom identify tool for ADFCompositeControl.
CustomControls_CSharp\ADFWebPart\Properties\AssemblyInfo.cs Assembly information for ADFWebPart.
CustomControls_CSharp\ADFWebPart\AJAXSharePointWebPart.cs Abstract class that provides code to workaround ASP.NET Asynchronous JavaScript and XML (AJAX) partial postback problems in SharePoint.
CustomControls_CSharp\ADFWebPart\MapGridViewWebPart.cs Implementation code for a Web Part that requires a ScriptManager and contains a GridView in an UpdatePanel, a Map, and a MapResourceManager control. Contains implementation code for interaction between tabular results in the GridView and graphics in the map.
CustomControls_CSharp\ADFWebPart\MapGridViewWebPartDesigner.cs Implementation for rendering control at design time.
CustomControls_CSharp\ADFWebPart\MapWebPart.cs Implementation code for a Web Part that contains a Map, MapResourceManager, Toolbar, and Toc control.
CustomControls_CSharp\ADFWebPart\MapIdentify.cs Implementation code for a custom identify tool in MapWebPart.
CustomControls_CSharp\ADFWebPart\Utility.cs Utility classes for the Web Part controls.
CustomControls_CSharp\CustomControlsWeb\AddWebPartOnClick.aspx Contains buttons to add Web Part controls and remove all parts from the page at run time.
CustomControls_CSharp\CustomControlsWeb\AddWebPartOnClick.aspx.cs Code behind. Implementation code to add the ADFWebPart controls to the page.
CustomControls_CSharp\CustomControlsWeb\DesignComposite.aspx Contains ADFCompositeControl at design time.
CustomControls_CSharp\CustomControlsWeb\DesignComposite.aspx.cs Code behind.
CustomControls_CSharp\CustomControlsWeb\DesignTimeUserControl.aspx Contains the custom WebUserControl at design time.
CustomControls_CSharp\CustomControlsWeb\DesignTimeUserControl.aspx.cs Code behind.
CustomControls_CSharp\CustomControlsWeb\WebUserControl.ascx Custom Web user control. Contains a Map, MapResourceManager, Toolbar, and Toc control.
CustomControls_CSharp\CustomControlsWeb\WebUserControl.ascx.cs Code behind the user control. Used to wire up buddy relationships.
CustomControls_CSharp\CustomControlsWeb\App_Code\TextFilePersonalizationProvider.cs Custom personalization provider enables the application to store personal information for authenticated users in a text file (App_Data\Personalization_Data). Personalization is required for the Web Part demos to function.
Download the C# files
CustomControls_VBNet\ADFCompositeControl\Properties\AssemblyInfo.vb Assembly information for ADFCompositeControl.
CustomControls_VBNet\ADFCompositeControl\MapToolTocControl.vb ADFCompositeControl implementation code. Contains a MapResourceManager, Map, Toolbar, and Toc control.
CustomControls_VBNet\ADFCompositeControl\MapIdentify.vb Custom identify tool for ADFCompositeControl.
CustomControls_VBNet\ADFWebPart\Properties\AssemblyInfo.vb Assembly information for ADFWebPart.
CustomControls_VBNet\ADFWebPart\AJAXSharePointWebPart.vb Abstract class that provides code to workaround ASP.NET Asynchronous JavaScript and XML (AJAX) partial postback problems in SharePoint.
CustomControls_VBNet\ADFWebPart\MapGridViewWebPart.vb Implementation code for Web Part that requires a ScriptManager and contains a GridView in an UpdatePanel, a Map, and a MapResourceManager control. Contains implementation code for interaction between tabular results in the GridView and graphics in the map.
CustomControls_VBNet\ADFWebPart\MapGridViewWebPartDesigner.vb Implementation for rendering control at design time.
CustomControls_VBNet\ADFWebPart\MapWebPart.vb Implementation code for Web Part that contains a Map and MapResourceManager, Toolbar, and Toc control.
CustomControls_VBNet\ADFWebPart\MapIdentify.vb Implementation code for a custom identify tool in MapWebPart.
CustomControls_VBNet\ADFWebPart\Utility.vb Utility classes for the Web Part controls.
CustomControls_VBNet\CustomControlsWeb\AddWebPartOnClick.aspx Contains buttons to add Web Part controls and remove all parts from the page at run time.
CustomControls_VBNet\CustomControlsWeb\AddWebPartOnClick.aspx.vb Code behind. Implementation code to add the ADFWebPart controls to the page.
CustomControls_VBNet\CustomControlsWeb\DesignComposite.aspx Contains ADFCompositeControl at design time.
CustomControls_VBNet\CustomControlsWeb\DesignComposite.aspx.vb Code behind.
CustomControls_VBNet\CustomControlsWeb\DesignTimeUserControl.aspx Contains the custom WebUserControl at design time.
CustomControls_VBNet\CustomControlsWeb\DesignTimeUserControl.aspx.vb Code behind.
CustomControls_VBNet\CustomControlsWeb\WebUserControl.ascx Custom Web user control. Contains a Map, MapResourceManager, Toolbar, and Toc control.
CustomControls_VBNet\CustomControlsWeb\WebUserControl.ascx.vb Code behind the user control. Used to wire up buddy relationships.
CustomControls_VBNet\CustomControlsWeb\App_Code\TextFilePersonalizationProvider.vb Custom personalization provider enables the application to store personal information for authenticated users in a text file (App_Data\Personalization_Data). Personalization is required for the Web Part demos to function.
Download the VB.NET files

Download the files for all languages

See Also:

ArcGIS Online
Web Parts Personalization Providers