Showing posts with label Web ADF. Show all posts
Showing posts with label Web ADF. Show all posts

Sunday, December 21, 2008

Control "CONTROL_NAME" or type "CONTROL_TYPE" must be placed inside a form tag with runat=server

today morning i was migrating an Arcgis server application from 9.2 to 9.3 where i had some custom made tools in the toolbar, one of the tools is rebinding a gridview control and refreshing it. but i was getting a strange following message Control "FPLegend_CGresults" or type "Gridview" must be placed inside a form tag with runat=server.



the first moment i thought that esri changed the way we do callbacks but google a bit i found out the solution but im not convinced with the error since i have my control within a form tag with runat=server.

still invistigating into it but here is how you can fix the problem:

in you default.aspx <@ page..> add the following attribute EnableEventValidation="false"

in your default.aspx.cs override the following VerifyRenderingInServerForm() function like this

public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
//
}


hope this helps others

Wednesday, December 17, 2008

Print Map with ArcGIS Server

Last week, i was to do some simple map printing of an ArcGIS Server application, the first thing i thought of is Layout view of the map, why this approach won't do the job for me ??

the reason is that im calling SOAP API operation which are stateless operations and it won't effect the Mapservice so there is no way to get that done.

as a start i thought i will take the map image put and put it in another aspx and print it along with the legned that im generating dynamically.

in my application users don't want to display the whole legend, they want to display the legend of some specific layers.

one issue thta i faced in getting the Map Image is that i have 3 rourceitems
1- Graphics Layer
2- non-Cahced Service
3- Cached Service

getting the image the normal would get only the non-chached service image, but found a way to get the image from all the resources for printing.

soon i'll pasting the code with some screenshots.

stay tuned

UPDATE:

create a sub folder in ur project directory or anywhere you want and call it "tmp". the "tmp" folder will be used to save the generated image.

you an extra page lets call it PrintPage.aspx

<%@ Page language="c#" Inherits="Printing.PrintPage" CodeFile="PrintPage.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>PrintPage</title>
<style type="text/css">

</style>
</head>
<body style="margin:0 0 0 0">
<form id="Form1" method="post" runat="server">
<table border="0" width="100%" align="center">
<tr>
<td style="width: 671px" align="left"><img src="GenerateImage.aspx" id="MapImage" Width="671" Height="606" runat="server" style="border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid" /></td>
<td valign="top" align="left">
<asp:GridView id="GVLegend" runat="server" Width="129px" Height="63px" GridLines="Horizontal" EmptyDataText="No Legend" AutoGenerateColumns="False">
<Columns>
<asp:ImageField DataImageUrlField="LegendImage">
<ItemStyle Height="40px" Width="30px" />
</asp:ImageField>
<asp:BoundField DataField="LegendName" >
<ItemStyle Font-Size="Smaller" />
</asp:BoundField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>



the code behind PrintPage.aspx.cs


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ESRI.ArcGIS.ADF.Web;

namespace Printing
{
public partial class PrintPage : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
MapImage.Src = Session["MapImageURL"].ToString();
}
}

}



in you default.aspx add a button that causes a callback to this function

public void PrintMap()
{
string MapImageURL = GISFunctions.ExportMapImage(Map1, Page.Request.PhysicalApplicationPath + @"tmp\");
Session["MapImageURL"] = "tmp/" + MapImageURL;


Map1.CallbackResults.Add(GeneralUtilities.Utilities.GetCallBack(null,null,"javascript","window.open('" + "PrintPage.aspx', 'PrintWindow', 'dependent=yes ,width=800, height=500, status=no, toolbar=no, menubar=yes, location=no, resizable=yes, scrollbars=yes');"));
mapstring = Map1.CallbackResults.ToString();
}


the ExportMapImage function code

public static string ExportMapImage(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map ADFMap, string OutputPath)
{
System.Collections.Generic.List<System.Drawing.Image> bitmaps = new System.Collections.Generic.List<System.Drawing.Image>();
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf in ADFMap.GetFunctionalities())
{
if (mf != null)
{
ESRI.ArcGIS.ADF.Web.MapImage mapImage = mf.DrawExtent(ADFMap.Extent);

mapImage = mf.DrawExtent(ADFMap.Extent);
if (mapImage == null)
continue;
if (mapImage.GetImage() != null)
{
bitmaps.Add(mapImage.GetImage());
}
}
}

System.Drawing.Bitmap newImg = new System.Drawing.Bitmap(Convert.ToInt16(ADFMap.Width.Value), Convert.ToInt16(ADFMap.Height.Value));

System.Drawing.Graphics imgGraphics = System.Drawing.Graphics.FromImage(newImg);
int i = bitmaps.Count - 1;
while (i >= 0)
{
imgGraphics.DrawImage(bitmaps[i], 0, 0, Convert.ToInt16(ADFMap.Width.Value), Convert.ToInt16(ADFMap.Height.Value));
i += -1;
}
long Ticks = DateTime.Now.Ticks;
string ImagePath = OutputPath + "mapimage" + Ticks + ".jpg";
newImg.Save(ImagePath, System.Drawing.Imaging.ImageFormat.Jpeg);

return "mapimage" + Ticks + ".jpg";
}


in the same way, you can add the legend next to the map, the reason why i didn't add it in code in the im displaying the legend based on different criterias which i didn't want to confuse others including it my code, but still if u need to know how to generate the legend, can can mail me.

Tuesday, December 9, 2008

ArcGIS Server 9.3 & AjaxControlToolKit Javascript Errors

many of the projects that i develop have ajax in them and i spicifically i use AjaxControlToolKit, well i had a couple of mapping applications developed in 9.2 and they use AjaxControlToolKit and projects works like a charm but when migrating to 9.3 have faced javascript errors that i couldn't solve , the following:

Sys.InvalidOperationException: Type Sys.Timer has already been registered.

Sys.InvalidOperationException: Type AjaxControlToolkit.BoxSide has already been registered.

Sys.InvalidOperationException: Type AjaxControlToolkit.Animation.Animation has already been registered.

well i have already posted a thread on ESRI forum here, and i got no responese till now, digging more into this issue, it turns out that when having AjaxControlToolkit.dll in ur bin directory and referencing it in ur project causes these errors only with 9.3 controls, invistigating more i found out that AjaxControlToolkit.dll is registered in the windows assembly when installing ArcGIS Server 9.3.

if u want things to work well, just reference the toolkit .dll from .NET assemblies, you will find it there and everything should work well, im talking about version 1.0.10920.32880 but if you want version 3.0.20229.20843 or higher to work with 9.3 ADF, you need to follow this article.