ThinkGeo.com    |     Documentation    |     Premium Support

ContextMenu - Error binding to target method

Created a simple ContextMenu for map and getting the following error :





         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Lucida Console";font-size: .9em}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
        

Server Error in '/' Application. 


Error binding to target method.


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: Error binding to target method.




Code below:


 

        protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

                CreateContextMenu();                

            }

        }





        private void CreateContextMenu()

        {

            ContextMenu menuOnMap = new ContextMenu("MapMenu", 100);



            ContextMenuItem panItem = new ContextMenuItem("Pan Map");

            panItem.Click += new EventHandler<ContextMenuItemClickEventArgs>(panItem_Click);



            menuOnMap.MenuItems.Add(panItem);

            Map1.ContextMenu = menuOnMap;

        }



        void panItem_Click(object sender, ContextMenuItemClickEventArgs e)

        {


            //Debugger does not reach here before error occurs.

        }




 


Any suggestions??


 


Thanks in advance,


Cruz



Cruz, 


We couldn’t recreate this problem. Here is our test demo which works fine; could you have a try on your machine? Please make sure you are using the latest version 3.1.16 (you can use the static property Map.Version to check it).
 
Thanks,
 
Ben

416-Post5316WebSite.zip (3.81 KB)

The version is MapSuiteCore:3.1.16;WebEdition:3.1.16. Testing further, this error is coming up on any event fired on the webform just having the Map on the same page. Could there be a known issue with installing the Full version with the evaluation version installed? This project worked fine with previous eval versions. I just upgraded to the full version, cleaned up some code to handle changes and now this comes up. The stack trace is the following: 
  
 Stack Trace:  
  
 [ArgumentException: Error binding to target method.] 
    System.Delegate.CreateDelegate(Type type, Object target, String method, Boolean ignoreCase, Boolean throwOnBindFailure) +7575934 
    System.Delegate.CreateDelegate(Type type, Object target, String method) +12 
    ThinkGeo.MapSuite.WebEdition.ContextMenuItem.x7f7af3ab7e11f7b1(Object x28db80135f012008) +160 
    ThinkGeo.MapSuite.WebEdition.ContextMenu.x37bbd6189884be38(Object x28db80135f012008) +124 
    ThinkGeo.MapSuite.WebEdition.Map.xd0abb09081f6d90c() +71 
    ThinkGeo.MapSuite.WebEdition.Map.LoadViewState(Object savedState) +646 
    System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +183 
    System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +134 
    System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +221 
    System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +134 
    System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +221 
    System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +134 
    System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +221 
    System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) +134 
    System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +221 
    System.Web.UI.Page.LoadAllState() +312 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1661 
  
   


Ben, I have viewed your example and do not get your results. I comment out the            " panItem.Click += new EventHandler<ContentMenuItemClickEventArgs>(panItem_Click); " and my project works… Could I possibly have a bad reference to an old version? what can I look for, any suggestions? 
  
 Thanks again, 
  
 Cruz

Cruz, 
  
 Evaluation Edition and Full Edition work side by side. We had a test installing the evaluation first and install the full edition later, and the above sample works fine under both situations. That’s very strange it doesn’t work on your machine. 
  
 Can you try the following ways to see if we can figure it out? 
 1, you said it works fine with an evaluation edition, can you double check if the above sample still works with that evaluation edition on your machine? If yes, what is its version? 
 2, if it is working with the evaluation edition, can you replace the reference MapSuiteCore.dll and WebEdition.dll with the Full release one? If the problem occurs just by doing this replacement, we can say something wrong with your full release assemblies. 
  
 Also, please let me know more about your environment, like the browser, the system and the Visual Studio editions. 
  
 Thanks, 
  
 Ben 


Cruz, also can you try the sample under Samples -> GettingStarted -> AddAContextMenu.aspx along with our product, does that work fine? 
  
 Ben 
  


Hi,


I have encountered the same error (Error binding to target method) when using ContextMenu in Content Page with Master Page. But after I change the Content Page to a single HTML page which is the same as the sample code, the error disappears and the ContextMenu works. It looks like the ContextMenu doesn't work in Content Page.


 


Best Regards,


YV 


 



YV, 
  
 We used to have the issue that the map doesn’t work well in Content Page, and we figured it out finally. So just let you know if you want to use context menu in content page, just go ahead to get the latest assembly and it should work. 
  
 BTW, I noticed this is your first message, welcome to the community and thanks for sharing! 
  
 Thanks, 
  
 Ben  


Ben/YV, thanks for the quick responses and information.  
  
 However, in reviewing project structure, I still was having the problem. The good news - In continuing my research I found out some new discoveries. First, I am using AJAX 3.5 controltookit and well as another 3rd party control suite (from a company called Infragistics) that utilizes AJAX as well. In both control toolkits - there is a tab container control that is causing the error. When embedding the Map control in one of these Tab controls and trying to use a menu click event, my web application errors out with the above error ‘Error binding to target method’. So, somehow these controls are conflicting eachother. I know that this was working fine with one of your previous versions of the evaluation version of the ‘Web Map Suite’ but at least I know what not to do for now! :) 
  
 soooo… If you want to test out the Map control (with that same example given above) in an AJAX 3.5 TabContainer to verify I am not going crazy that would be sooo great. 
  
 Thanks again for your help, 
  
 Cruz

Cruz, 


I see the problem; you are not crazy at all. :-)
 
The context menu in our map component is not a web control, we have to rewire its events after a postback otherwise as the client id will change and the events will not be hooked up. By default, we look up the event’s delegate within its naming container to rewire it, but in your case, map’s naming container is the TabContainer and of cause we cannot find the delegate.
 
I think you have worked it around, but still here is one solution for you.  Put the map within a user control and the context menu will work fine. Please have a look at the attached demo.
 
Thanks,
 
Ben

437-Post5316.zip (4.49 KB)