我對JavaScript非常陌生,但不幸的是,這是我必須使用的溫度計圖表。我需要獲取ASP標籤文本的值,然後將其存儲到將用於設置圖表值的JavaScript變量中。將標籤文本值轉換爲javascript變量
由於某些原因,它根本不存儲該值,圖表顯然沒有所需的值。再一次,我對JavaScript非常新,所以請好好。 :)這是我到目前爲止。
下面是ASPX頁面的一部分:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script>
window.onload = function() {
// Create the Thermometer chart. The arguments are: the canvas ID, the minimum,
// the maximum and the indicated value.
var grossSales = $('#<%= MtdLBL.ClientID %>').next().text;
var thermometer = new RGraph.Thermometer('salesThermometer', 0, 180000, parseInt(grossSales.valueOf))
// Configure the thermometer chart to look as you want.
.Set('chart.gutter.left', 45)
.Set('chart.gutter.right', 45)
.Set('chart.colors', ['rgba(255,0,0,1)'])
.Set('chart.units.pre', '$')
// Now call the .Draw() method to draw the chart.
.Draw();
}
</script>
<link href="Charts/RGraph/demos/demos.css" rel="stylesheet" type="text/css" />
<script src="Charts/RGraph/libraries/RGraph.common.core.js" type="text/javascript"></script>
<script src="Charts/RGraph/libraries/RGraph.thermometer.js" type="text/javascript"></script>
</asp:Content>
這是從後臺代碼:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["TeamID"] == null || Session["TeamID"] == "")
{
Response.Redirect("~/Default.aspx");
}
else
{
//Populate department average
double deptAvg = achievementData.DeptAverage();
DeptAvgValueLBL.Text = deptAvg.ToString("P0");
//Get sales data
Sales getSalesData = new Sales();
MtdLBL.Text = getSalesData.GrossSalesByTeam(Session["TeamID"].ToString());
}
}
你爲什麼讓你的JavaScript代碼的正確控制後調用的.next()? – catfood
我在這裏發現了一個類似的問題http://stackoverflow.com/questions/7431464/how-to-use-javascript-to-get-asp-net-web-forms-labels-value。但是,當我刪除.next()它仍然不起作用。 – cal5barton