为什么谷歌图表不显示在添加RUNAT =&QUOT时,服务器"? [英] Why google chart not display when add in runat="server"?

查看:144
本文介绍了为什么谷歌图表不显示在添加RUNAT =&QUOT时,服务器"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个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.net自动命名它变成你的chart_div1变成类似ctl00_ContentPlaceHolder1_chart_div1。如果你的目标ASP.NET 4.0你可以在页面指令,刚刚成立的ClientIDMode =静态这个设定。这将产生的ID正是因为你有他们在你的控制。

Perhaps it's asp.net 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;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆