2

I'm having problems loading a simple chart via web services...

I load user controls as html and send them back to the page via a web service to display the charts in a jquery ui popup dialog:

[WebMethod]
        public string GetProfileForm(string formType)
        {
            Page page = new FormlessPage();
            PersonalDetails ctl = (PersonalDetails)page.LoadControl("/Toolbox/Controls/PersonalDetails.ascx");
            page.Controls.Add(ctl);
            using (StringWriter writer = new StringWriter())
            {
                HttpContext.Current.Server.Execute(page, writer, false);
                return writer.ToString();
            }
        }

Whether the javascript is in the user control or created after the user control has loaded, not only does the chart not load, but the whole page just hangs:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PersonalDetails.ascx.cs" Inherits="ToolBox.Controls.PersonalDetails" %>

<div id="gchart_div"></div>

<script type="text/javascript">
    google.load('visualization', '1.0', { 'packages': ['corechart'] });
    google.setOnLoadCallback(drawChart);
    function drawChart() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Topping');
        data.addColumn('number', 'Slices');
        data.addRows([
          ['Mushrooms', 3],
          ['Onions', 1],
          ['Olives', 1],
          ['Zucchini', 1],
          ['Pepperoni', 2]
        ]);

        // Set chart options
        var options = { 'title': 'How Much Pizza I Ate Last Night',
            'width': 400,
            'height': 300
        };

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('gchart_div'));
        chart.draw(data, options);
    }
</script>

my Site.Master page has the API call:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>

If I run the javascript on any other page ( ie one not loaded as a control through web services), it works fine.

Is this a limitation of google charts? or am I doing something wrong?

I have tried moving the javascript out into the page housing the popup, but this has the same effect.

Thanks in advance... Dan

4

0 回答 0