从asp.net代码中调用jquery函数
我需要在引导中创建饼图。。在谷歌搜索中,我得到了一段代码。。 如何从asp.net codebehind调用此函数?如何将数据库中的数据提供给piechart从asp.net代码中调用jquery函数,asp.net,Asp.net,我需要在引导中创建饼图。。在谷歌搜索中,我得到了一段代码。。 如何从asp.net codebehind调用此函数?如何将数据库中的数据提供给piechart $.plot('#placeholder', data, { series: { pie: { show: true } } }); 试一试 受保护的void myButton(对象发送方,事件参数e) { ScriptManager.RegisterStartup
$.plot('#placeholder', data, {
series: {
pie: {
show: true
}
}
});
试一试
受保护的void myButton(对象发送方,事件参数e)
{
ScriptManager.RegisterStartupScript(this.Page,this.GetType(),“tmp”,
“占位符(参数…)”,false);
}
我建议相反,让jQuery代码通过ASP.NET AJAX页面方法调用服务器端,如下所示:
$(document).ready(function() {
// For example's sake, this will ask the database for
// data upon the DOM being loaded
$.ajax({
type: "POST",
url: "PageName.aspx/GetPieChartData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result) {
// Plot result data returned from AJAX call to server
$.plot('#placeholder', result.d, {
series: {
pie: {
show: true
}
}
});
}
});
});
注意:您需要将
PageName.aspx
重命名为实际的.aspx页面名称
代码隐藏:
[WebMethod]
public static string GetPieChartData()
{
// Go to database and retrieve pie chart data
string data = GetPieChartDataFromDatabase();
return data;
}
注意:ASP.NET AJAX页面方法会自动对返回的数据进行JSON编码,因此不需要在服务器端进行序列化调用。另外,请注意ASP.NET AJAX页面方法必须是静态的,因为它们与实际页面类本身没有交互
[WebMethod]
public static string GetPieChartData()
{
// Go to database and retrieve pie chart data
string data = GetPieChartDataFromDatabase();
return data;
}