我有这个DIV:
<div> <asp:Literal ID="lt" runat="server"></asp:Literal> </div> <div id="chart_div1" style="width: 900px; height: 500px;"></div>它运行良好,并能显示柱状图非常精细。该bindchart()函数我把我的codebehind:
It run well and can show the barchart very fine. The bindchart() function I put in my codebehind:
.. str.Append(@"<script type=text/javascript> google.load( *visualization*, *1*, {packages:[*corechart*]}); google.setOnLoadCallback(drawChart); function drawChart() { ... str.Append(@"<script type=text/javascript> google.load( *visualization*, *1*, {packages:[*corechart*]}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); .. str.Append(" var chart = new google.visualization.ColumnChart(document.getElementById('chart_div1'));"); str.Append(" chart.draw(data,{isStacked:true, width:900, height:350, hAxis: {showTextEvery:1, slantedText:true}});}"); ... str.Append("</script>"); lt.Text = str.ToString().TrimEnd(',').Replace('*', '"'); ...但是,当我添加
"runat="server"为ID =chart_div1
to id = "chart_div1"
<div> <asp:Literal ID="lt" runat="server"></asp:Literal> </div> <div id="chart_div1" runat="server" style="width: 900px; height: 500px;"></div>然后我可以看到格显示为空白,无法看到图形!为什么它是如此奇怪的这样呢?我需要把=服务器,这样我可以在我的code认识落后于进一步进程的ID。任何建议?
then I can see the div appear as blank and cannot see the graph ! Why it is so strange like that ? I need to put runat="server" so that I can recognize the id in my code behind for further process. Any suggestion ?
推荐答案也许是asp自动命名它变成你的chart_div1变成类似ctl00_ContentPlaceHolder1_chart_div1。如果你的目标ASP.NET 4.0你可以在页面指令,刚刚成立的ClientIDMode =静态这个设定。这将产生的ID正是因为你有他们在你的控制。
Perhaps it's asp auto naming which turns your "chart_div1" into something like "ctl00_ContentPlaceHolder1_chart_div1". If you're targeting ASP.NET 4.0 you can switch this off in page directive, just set ClientIDMode="Static". This will produce ID's exactly as you have them in your controls.
更多推荐
为什么谷歌图表不显示在添加RUNAT =&QUOT时,服务器&QUOT;?
发布评论