我正在尝试将值从代码背后传递给JavaScript。我已经尝试了所有方法,但是当我尝试显示时,它给出了未定义的信息。
这是我后面的代码
try
{
int total = manager.GetAllBooks().Tables[0].Rows.Count;
lblmsg1.Text = total.ToString();
filesPercentage.Value = total.ToString();
}
catch (Exception ex)
{
throw ex;
}
这是JavaScript:
var pct = document.getElementById("<%=filesPercentage.ClientID%>").value;
alert(pct);
我将不胜感激。我正在尝试使用chart.js绘制图表,并尝试传递动态值而不是静态值。
答案 0 :(得分:0)
尝试一下 定义属性
protected string FilesPercentage
{
set {
ViewState["x"]=value;
}
get
{
if(ViewState["x"] != null)
return (string)ViewState["x"];
}
}
在您的Java脚本中:
alert('<%=FilesPercentage%>')
在您的代码背后:
try
{
int total = manager.GetAllBooks().Tables[0].Rows.Count;
lblmsg1.Text = total.ToString();
FilesPercentage = total.ToString();
}
catch (Exception ex)
{
throw ex;
}