Welcome to ESRI Blogs

Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

Rex Hansen, a Product Engineer for the .Net Web ADF, contributed this post:

Update: The post below applies to ArcGIS Server 9.2. Click here to see the 9.3 instructions.

The organization of information within a Web site can be challenging, especially when attempting to accommodate multiple end users with different work habits and capabilities. To support this situation, many Web sites utilize some form a portal technology which can provide a framework to modularize information and personalize its presentation. First introduced in ASP.NET 2.0, the Web Parts framework fulfills this need by providing an ASP.NET solution for portal developers. In general, ASP.NET Web Parts are controls that enable developers to encapsulate related functionality and give end users the ability to modify the content, appearance, and behavior of Web pages directly in a browser.

There are a number of options for building an ASP.NET Web Part in Visual Studio 2005: drag and drop Web Part controls in a page, build a Web user control, or create a custom Web Part control. In most cases, Web Parts are supposed to be added\removed at runtime during a user session, so dragging and dropping Web Part controls in a page at design-time does not offer a realistic solution. Web ADF controls will work in user controls, but not if the user control is in a Web Part. This problem is rooted in managing state and control ids for callbacks and cannot be overcome in ArcGIS Server 9.2. This leaves the last option, a custom Web Part control, which also gives you the most control over how the Web Part functions. There are two stages to consider here: support for Web ADF controls in a custom Web Part and deployment of the Web Part. In essence, getting Web ADF controls to work in a custom Web Part involves building a custom composite Web control that inherits from System.Web.UI.WebControls.WebParts.WebPart. Other than the standard pattern for creating a custom composite Web control, such as adding controls during CreateChildControls(), a number of Web ADF control specific issues must be considered:

  • In a custom Web Part, Web ADF controls are added dynamically. During a request to a page, the page and its controls (including the Web Part) iterate through their lifecycle. This becomes important when dealing with resources added to a resource manager. Once added, they are maintained in state and retrieved when the resource manager is recreated during the control lifecycle. So as not to keep re-adding resources every time the resource manager is created during the Web Part lifecycle, you need to check session state for the presence of the resource items. If present, do not re-add the resources.
  • A set of HTML hidden input elements (fields) are injected in the page at runtime if a Web ADF control is present. These fields store information about the current tool, map mode, and screen coordinates associated with tool interaction in the map, etc. One field, ESRIWebADFHiddenFields, stores a list of all the other field names (input values). This list is used to include the other field values in a callback request. If the Web ADF controls are added after the initial request to the page (such as what happens when a Web Part is added during a full postback to the page), the ESRIWebADFHiddenFields value is empty. As a result, tool interaction with the map is not functional. To workaround this issue, you need to manually set the value of the ESRIWebADFHiddenFields element. Note this will only affect Web Parts that are added after initial page load. If a Web Part is added during initial page load, these fields will be set correctly. Adding more than one Web Part with a Web ADF Map and Toolbar will likely cause conflicts and render some tool interaction with the map non-functional. There is no easy way to overcome this in 9.2. As a result, it is best to add only one Web Part with a Map-Toolbar per page.

On to working with SharePoint - Building a portal site which uses Web Parts can be time consuming; integrating the site into other enterprise systems can be difficult and inefficient; and lastly, managing the site can be overly complex and convoluted. In an attempt to manage enterprise content, intelligence and search systems effectively, Microsoft has created Microsoft Office SharePoint Server 2007, or MOSS for short. MOSS is good for what it claims to do (be an all encompassing enterprise system for sharing information), but it is not simple. Like many software products, more capability means greater complexity. One option for customizing the presentation of content and providing access to business logic is developing custom ASP.NET Web Parts and deploying them on a SharePoint server. An ASP.NET Web Part can be deployed relatively easily with SharePoint 2007. The SharePoint SDK includes a WebPart class which derives from the ASP.NET WebPart. The SharePoint WebPart class offers a few benefits, such as cross-page and non-WebPart connections, which primarily facilitate backward compatibility with SharePoint 2003. For more information on Web Part development with SharePoint 2007, Scott Guthrie provides a bevy of valuable information and links in his blog post Writing Custom WebParts for SharePoint 2007. You can use Sahil Malik’s walkthrough at the beginning of the post to get started creating a custom ASP.NET Web Part.

There are a few issues to consider when deploying a Web Part that contains Web ADF controls in SharePoint 2007:

  • SharePoint 2007 was designed to function using the full page postback pattern. As a result, tools in a Web ADF Toolbar may need to trigger a full postback within a custom Web Part to communicate with other parts in the page. Unfortunately the postback event never gets to the tool, so some additional code is required to raise the post back event to the correct control (e.g. Map). See the sample code for more details.
  • The SharePoint 2007 server may not have session state enabled, which is necessary for the Web ADF controls to function. If not enabled, SharePoint will return a fairly ambiguous error when attempting to add your custom Web Part to the SharePoint server.

The 9.3 Web ADF will resolve many of the limitations and issues encountered when working with 9.2 Web ADF controls in a Web Part. 9.3 Web ADF controls will be fully supported for use in custom user and composite controls, both of which may be deployed as a Web Part. Multiple Web Parts containing multiple Web ADF controls can function within the same application. The use of ESRIWebADFHiddenFields will be reduced if not removed. And full postbacks initiated by toolbar items will be supported internally.

The sample code includes two projects. The class library project contains the custom Web Part with a MapResourceManager, Map and Toolbar control. The file system Web application contains a simple aspx page designed to emulate a runtime scenario where an end user wants to add a Web Part within the current session. Note, to personalize the page (e.g. add a Web Part at runtime) the current session must be associated with an authenticated user. By default, a file system Web site will used integrated authentication. If deploying as a Web application in IIS, you will need to disable anonymous access to the Web application in IIS. Enabling integrated authentication may offer the easiest solution since you do not need to configure or explicitly set authentication details, instead the authenticated user will be the user account under which the client (browser) is running.

The default personalization provider for ASP.NET 2.0 is SQL Express. If you do not have SQL Express installed, a personalization store will not be created (upon initial execution of the application) and an error will be returned when attempting to add the custom Web Part to the page at runtime. To alleviate this requirement, I have added a custom personalization provider that uses text files. The code, markup, and discussion for this technique is provided here: http://msdn2.microsoft.com/en-us/library/aa479037.aspx

Download the sample code

Published Wednesday, February 27, 2008 10:45 AM by sterlingdq

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

Thank you for the useful information. How, if at all, will this change with the ArcGIS 9.3 release?
Wednesday, February 27, 2008 1:06 PM by Scott

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

Never mind about the 9.3 question, you answered in the post.
Wednesday, February 27, 2008 1:07 PM by Scott

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

I could not get the code in the application to run.  I opened the solution and ran the Default.aspx, but it throws [SqlException (0x80131904): Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.]

Are there any additional instructions to get this working locally that I could use?

Many thanks,

Chris

Thursday, February 28, 2008 6:13 AM by clj2289

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

Hi Chris,

I suspect you're encountering a problem generating the ASPNETDB.mdf in the Web application's App_Data folder. In most cases this will be created the first time you access the Web application, however there always seem to be exceptions. To add\remove WebParts at runtime, personalization must be enabled. Personalization requires an authenticated user. These users need to be stored in some fashion (e.g. SQL Express database, MS Access, Windows users and groups, etc.) that's accessible to the ASP.NET Web application. Since I didn't include a user store or database in the example, ASP.NET will attempt to create the SQL Server Express database file ASPNETDB.mdf. This means you'll need SQL Server Express installed. The error message seems to indicate you have access to SQL Server Express, but the current authenticated user does not have a profile. Try the following steps in an attempt to create the ASPNETDB.mdf for the file system Web site:

1) Assuming the ADFWebPart solution is open in in Visual Studio 2005, select the ADFWebPartWebsiteFS file system Web site in Solution Explorer.
2) Navigate to and select the Website>ASP.NET Configuration menu. A browser should open and display the ASP.NET Website Administration Tool.
3) On the Security tab, click on Manage Access Rules. Click on the App_Data folder and confirm that you have the Allow permission set for all users and roles.
4) On the Provider tab, click on 'Select a single provider for all site management data'. The AspNetSqlProvider should be listed. Click on the Test link. This will return whether the connection to the SQL Server Express database succeeded.

Let me know how it goes when you get the chance.

Thanks,
-Rex

Thursday, February 28, 2008 1:27 PM by Rex Hansen

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

protected void InitializeMapExtent(MapResourceItem mapResourceItem)

       {

           IMapResource mapResource = mapResourceItem.Resource as IMapResource;

           Envelope envelope = mapResource.MapInformation.DefaultExtent;

           m_AdfMap.Extent = envelope;

       }

I am getting a error in line Envelope envelope = mapResource.MapInformation.DefaultExtent;

where mapResource is null.

Monday, March 10, 2008 3:22 AM by hem571

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

Usually this error indicates that the resource item definition string was incorrect. Take a look at the data source and resource string used by the ADFWebPart (the DataSource and Resource properties) and make sure they are valid. Thanks, -Rex
Thursday, March 13, 2008 10:16 PM by Rex Hansen

# How to change the Resource

Rex, Thanks for posting the sample code. My question is how to change the map resource. In a SharePoint site with the sample ADF Web Part added, I clicked "edit" at the upper right corner of the ADF Web Part, and selected the "Modify Shared Web Part" option. Then I opened the "Resources" category, and in the "Resource" text box, I changed the map service. But after the change, the map is not showing. I did debug in ADFWebPart.cs, and I saw the m_Resource value has been changed to the new one I put. The problem is that the Web Part map does not reflect the change of map resource. Do you have any suggestions? Thanks for your time!
Friday, March 14, 2008 1:34 PM by Naiqian Zhu

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

Dear Naiqian, i have the following code to change the map resource at run time , i hope to be helpfull for you. GISResourceItemDefinition definition = new GISResourceItemDefinition(); MapResourceItem MapResourceItem1 = new MapResourceItem(); MapResourceItem1.Name = NewMapService; definition.DataSourceDefinition = "localhost"; definition.DataSourceType = "ArcGIS Server Local"; definition.ResourceDefinition = "(default)@" + NewMapService; definition.DataSourceShared = true; MapResourceItem1.Parent = MapResourceManager1; MapResourceItem1.Definition = definition; DisplaySettings DisplaySettings = new DisplaySettings(); DisplaySettings.DisplayInTableOfContents = true; DisplaySettings.Visible = true; MapResourceItem1.DisplaySettings = DisplaySettings; MapResourceManager1.ResourceItems.RemoveAt(0); MapResourceManager1.ResourceItems.Insert(0, MapResourceItem1); Map1.Reset(); Map1.ZoomToFullExtent(); Map1.Refresh(); Regards,
Friday, March 14, 2008 2:38 PM by Rashed Mostafa

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

Rex

On both initialization and subsequent postbacks, the web part appears to consistently double post - that is, there is a second postback.  This causes CreateChildControls to be called twice, for example.  I can't imagine that is by design.  Are you aware of it?

TJ

Friday, March 28, 2008 7:46 AM by TJBNC

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

I build the sample application. I take the ADFWebPart.dll and copy it to the WSS server and place it into the C:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin folder. In the Home Team Site, I go to Site Actions>>Site Settings>>Web Parts I select New from the menu. The web part does not show up in the list. Any ideas?
Thursday, April 03, 2008 9:34 AM by Wherewhy

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

I solved my issue. I needed to add the SafeControl for the Web Part in the web.config in wss\virtualdirectories\80
Thursday, April 03, 2008 9:40 AM by Wherewhy

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

Hi Rex, Great post thank you and very relevant to me as I've been asked to put together a demonstrator using Web ADF controls within a Sharepoint portal. Just one question: What's the best way to develop against Sharepoint?Have you installed it locally? I'll need to demo from my laptop in places that may not have Internet access and wondering if there's a smart way of doing this without a monolithic install! Many thanks. Mark
Tuesday, April 08, 2008 7:38 AM by Mark

# Problems with identify and minimize button

This is a great help ,but I have found some problems. firt how can I build a table to see the results of the identify tool. and the other is that the identify and minimize option of webpart cause a problem to my dropdownbox that I have added it. When I use the identify button and minimize, my dropdownlist doesn't work correctly, For example this dropdownbox has some items but always the serverAction fuction receive the same listitem, this listitem was selected when I was using the identify and minimize, some help will be useful thanks.
Saturday, April 12, 2008 7:52 AM by vickuaeh

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

Rex, I've added a feature to the webpart base code you provided (Thanks for that). I use a spatial query to get all features within a polygon. What I'm attempting to do now is to change the extent of the map to the polygon selected. All my code runs correctly, but the extent does not change. I have a separate class that does the selection. public class SelectTool : IMapServerToolAction { void IMapServerToolAction.ServerAction(ToolEventArgs args) { // create map object Map adfMap = args.Control as Map; later on : //zoom to Pol feature ESRI.ArcGIS.ADF.Web.Geometry.Envelope env = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(); env.Union(GetGeometry(dr)); adfMap.Extent = env; } How do I get that environment to take effect in a class that's outside the base class?
Sunday, April 13, 2008 7:46 AM by Wherewhy

# maptips problems

Hello can you help me I have been trying to put a maptips but always i get the same mistake here is mi code protected MapTips m_AdfMaptips = null; inside CreateChildControls() m_AdfMaptips = CreateMaptips(); m_AdfMaptips.Layer = m_AdfMapResourceManager.ID + "::AGSMapResource::Escuelas2"; m_AdfMaptips.Map = m_AdfMap.ID ; Controls.Add(m_AdfMaptips); to create map tip protected MapTips CreateMaptips() { m_AdfMaptips = new MapTips(); m_AdfMaptips.ID = this.ID + "_ADFWebPartMaptips"; m_AdfMaptips.ClickImage=Page.ClientScript.GetWebResourceUrl(GetType(), "ADFWebPart.images.point.gif"); m_AdfMaptips.DefaultImage=Page.ClientScript.GetWebResourceUrl(GetType(), "ADFWebPart.images.blank.gif"); m_AdfMaptips.HoverImage=Page.ClientScript.GetWebResourceUrl(GetType(), "ADFWebPart.images.point.gif"); m_AdfMaptips.UseDefaultWebResources = true; m_AdfMaptips.BodyFormatString = "school: {school_name}"; m_AdfMaptips.HeaderFormatString = "School Name"; m_AdfMaptips.Visible = true; m_AdfMaptips.ShowOnlyWhenLayerIsVisible = true; return m_AdfMaptips; } to refresh maptips if makes zoom or something on map void MapTips_RefreshAll(object sender, EventArgs args) { m_AdfMaptips = CreateMaptips(); m_AdfMaptips.Layer = m_AdfMapResourceManager.ID + "::AGSMapResource::Schools2"; m_AdfMaptips.Map = m_AdfMap.ID; Controls.Add(m_AdfMaptips); } Some code i found in forums but don't run on the web part
Monday, April 14, 2008 6:28 PM by robbie

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

Hi Rex, Great post, but I'm intrigued by your references to 9.3. I'm intending to use the 9.3 Snapshot 1 to put together a demo Sharepoint app with a simple map control... Am I to take it from the above that I don't need to do anything special to manage state, etc if using 9.3? Many thanks, Mark
Friday, May 02, 2008 7:57 AM by Mark Lewin

# re: Using Web ADF controls in an ASP.NET Web Part and SharePoint 2007

Hi,

Thanks for useful information.

I am using ArcGIS Server 9.2 Web ADF, MOSS 2007 and ASP.NET 2005. I am using IQueryFunctionality.Query. I am sending QueryFilter and I set ReturnADFGeometry to true. But I am not getting "ADF Geometry" in response datatable.

Could you please let me know if any faced any problem.

Regards,

Venkat

Thursday, August 28, 2008 2:09 AM by kvenkatj

Leave a Comment

(required) 
required 
(required)