none
How To Convert JSON Object to Control Chart Object RRS feed

  • Question

  • I'm trying to pass the reference of a Control Chart object through JSON to my codebehind using Page Methods.  I've created a JSON object, but I'm guessing it's probably not defined correctly.  On top of that, I don't know how to reference it in my webmethod -- I'm receiving it as an object, but when I try to convert/cast it to a Chart control, I get the following error message:

    Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' to type 'System.Web.UI.DataVisualization.Charting.Chart'.

    My chart declaration is barebones:

    <asp:Chart id="chFA1SM1" runat="server"></asp:Chart>

    My javascript looks like:

    function getData() {
                ct = {"ID": "chFA1SM1"};
                PageMethods.getData(ct, function (returnValue) {
                    alert(returnValue.Name + ":" + returnValue.Value);
                });
            }

    And my webmethod codebehind:

            [WebMethod]
            public static void getData(object ct)
            {
                Chart chrt = (Chart)ct;
    
                LoadGraphFA1SM1();
            }

    Help me C# forum community, you're my only hope...


    Sunday, January 26, 2014 3:57 PM

All replies

  • Hi Puffster,

    In my opinion, this thread is related to ASP.NET forum. This forum is to discuss problems about C# programming. So please post thread on ASP.NET forum for more effective response. Thank you for understanding. Please refer to the following link. http://forums.asp.net/.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 27, 2014 7:51 AM
  • Just reposted it, thanks for the suggestion.  The reason I posted it here is because I believe the issue is syntactical -- once the object is getting passed into my C# code behind, I'm not sure how to convert it into a Control Chart to work with...but let's see what happens!!

    Have a Great Week!!

    Monday, January 27, 2014 6:24 PM