我在通过网络服务加载简单图表时遇到问题......
我将用户控件加载为html并通过Web服务将它们发送回页面,以在jquery ui弹出对话框中显示图表:
[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();
}
}
javascript是在用户控件中还是在用户控件加载后创建的,不仅图表没有加载,而且整个页面都挂起了:
<%@ 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>
我的Site.Master页面有API调用:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
如果我在任何其他页面上运行javascript(即未通过Web服务加载控件),它可以正常工作。
这是谷歌排行榜的限制吗?或者我做错了什么?
我尝试将javascript移到弹出窗口的页面中,但这有同样的效果。
提前致谢... 丹