gpt4 book ai didi

c# - javascript ASP.NET hiddenfield 从后面的代码中获取值

转载 作者:行者123 更新时间:2023-11-30 18:46:58 24 4
gpt4 key购买 nike

我正在尝试将我的代码集成到 Google Chart API。我想从后面的代码中手动设置谷歌图表标题和轴列名称。我试过下面的代码但没有用。有什么建议吗?

ASPX文件

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { "packages": ["corechart"] });
function drawProgrammingChart() {
var data = new google.visualization.DataTable(operationdetails, 0.5);
var chart = new google.visualization.LineChart(document.getElementById("divprog"));
**var xAxis = document.getElementById("txtXAxisName");**
**console.log(xAxis);**
var yAxis = document.getElementById("txtYAxisName");
chart.draw(data, {
title: "Visualization Satisfaction", hAxis: { title: "Programming method" }, vAxis: { title: "Units" }
});
}
google.setOnLoadCallback(drawProgrammingChart);
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div id="divprog" style="width: 750px; height: 350px;">
</div>
<asp:HiddenField ID="txtXAxisName" runat="server" />
<asp:HiddenField ID="txtYAxisName" runat="server" />
</asp:Content>

在后面的代码中,我想手动设置隐藏字段值。

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = generateDataTable();
**txtXAxisName.Value = "Days";**
txtYAxisName.Value = "Duration";
LoadChart(dt, "operationdetails");
}

}
private void LoadChart(DataTable table, string jsName)
{
Page.ClientScript.RegisterStartupScript(
this.GetType(),
jsName, string.Format("var {0} = {1};", jsName, new Bortosky.Google.Visualization.GoogleDataTable(table).GetJson()), true);
}

获取元素txtAxisName时,获取null。

最佳答案

您可以尝试以下方法:

var yAxis = document.getElementById('<%# txtYAxisName.ClientID %>');

关于c# - javascript ASP.NET hiddenfield 从后面的代码中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13442174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com