This project is read-only.

eventhandler keeps posting back

May 22, 2009 at 6:05 PM



I've downloaded the latest bits (31229), and am trying to subscribe to the 'OnZoomEnd' event, however when I do this the page keeps posting back (when the map loads,  the event goes of and does a postback, loads the page again, etc.)


When I try to use the 'OnMoveEnd' event, the page also does a postback immediately on load, but then throws the following exception:


Server Error in '/' Application.


Object of type 'System.EventArgs' cannot be converted to type 'Artem.Web.UI.Controls.GoogleEventArgs'.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 


Exception Details: System.ArgumentException: Object of type 'System.EventArgs' cannot be converted to type 'Artem.Web.UI.Controls.GoogleEventArgs'.


Source Error: 


Line 331:            }

Line 332:

Line 333:            if (handler != null) handler.DynamicInvoke(sender, e);

Line 334:        }

Line 335:


Source File: D:\Projects\Net Industry\OrangeLeaf\VindCreatieven\Main\Source\Artem.GoogleMap\GoogleEventList.cs    Line: 333 


Stack Trace: 


[ArgumentException: Object of type 'System.EventArgs' cannot be converted to type 'Artem.Web.UI.Controls.GoogleEventArgs'.]

   System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr) +7536269

   System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) +211

   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +228

   System.Delegate.DynamicInvokeImpl(Object[] args) +84

   System.Delegate.DynamicInvoke(Object[] args) +7

   Artem.Web.UI.Controls.GoogleEventList.RaiseEvent(Object sender, String key, String args) in D:\Projects\Net Industry\OrangeLeaf\VindCreatieven\Main\Source\Artem.GoogleMap\GoogleEventList.cs:333

   Artem.Web.UI.Controls.GoogleMap.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) in D:\Projects\Net Industry\OrangeLeaf\VindCreatieven\Main\Source\Artem.GoogleMap\GoogleMap.cs:1208

   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13

   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175

   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565



Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.3074


The aspx just looks like this:


    <artem:GoogleMap ID="GoogleMap1" runat="server" Width="360px" Height="200px" 


Latitude="52.1229" Longitude="4.7879" Zoom="12" 


        ShowScaleControl="true" OnMoveEnd="OnMoveEnd" OnZoomEnd="OnZoomEnd">




<artem:GoogleMarker Latitude="52.1229" Longitude="4.7879" Title="Hello World"  />








the codebehind looks like this:




        protected void OnZoomEnd(object sender, GoogleEventArgs e)










        protected void OnMoveEnd(object sender, GoogleEventArgs e)












May 22, 2009 at 9:56 PM


Some more background information:

- The server error only occurs in the 4.1 version, the 4.0 version does however have the 'postback loop' bug.

I've been able to solve my issue now by suspending the raising of server events until after the 'OnClientLoad' event of the map.

I did this by setting a new field 'enableServerEvents' on the map, and modifying the GoogleMap..js to:

    raiseEvent: function(handler, args) {;
        if (handler && this.enableServerEvents) {
            if (args)
                handler = handler.replace("ARGS", args);


    <script type="text/javascript">
        function enableServerEvents()
            GoogleMap1.enableServerEvents = true;

            <artem:GoogleMap ID="GoogleMap1" runat="server" Width="360px" Height="200px"
                Latitude="52.1229" Longitude="4.7879" Zoom="12"
                ShowScaleControl="true" OnClientMapLoad="enableServerEvents()" OnZoomEnd="OnZoomEnd" OnMoveEnd="OnMoveEnd"  >
                    <artem:GoogleMarker Latitude="52.1229" Longitude="4.7879" Title="Hello World"  />



Sep 7, 2009 at 12:53 PM
Edited Sep 7, 2009 at 12:59 PM

Hi wtijsma:

Thanks for the tip but this is a partial solution. If the GoogleMap control is inside an UpdatePanel and the ZoomEnd Event is wired, the GoogleMap control lose the zoom persistence after the first postback and you have to set manually the zoom level inside the OnZoomEnd event handler:

 public void GoogleMap1_ZoomEnd(object sender, GoogleZoomEventArgs e)
  GoogleMap1.Zoom = (int)e.NewLevel; //I don't Know why Google1.Zoom property is an Interger but GoogleZoomEventArgs.NewLevel is a Double

             //Do what ever you want here.......

By the way, The new zoom level is also wrong. To fix it you have to add the following


 else if(pair.Length == 1)
         this.NewLevel = JsUtil.ToDouble(pair[0]);

to the line 270 of the file GoogleEventArgs.cs

Does somebody have a better workarround?

Thanks in Advance.

P.D you can set this.enableServerEvents = true; after the GoogleMap client load method (file GoogleMap-4.1.js line 1047) avoiding to wire up the OnclientMapLoad every time you need to use server events of the GoogleMap control