繁体   English   中英

如何从服务器端asp.net填充JavaScript变量?

[英]How to fill JavaScript variable from server-side asp.net?

我有这个Google Chart中的JavaScript函数

function drawVisualization() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
    ['Name',                                                                 'Manager', 'Tooltip'],
    ['Mike',                                                                 null,      'The President'],
    [{v: 'Jim', f: 'Jim<br/><font color="red"><i>Vice President<i></font>'}, 'Mike',    null],
    ['Alice',                                                                'Mike',    'wonderland'],
    ['Bob',                                                                  'Jim',     'Bob Sponge'],
    ['Carol',                                                                'Bob',     null]
  ]);

  // Create and draw the visualization.
  new google.visualization.OrgChart(document.getElementById('visualization')).
      draw(data, {allowHtml: true});
}

我不明白如何填充用JavaScript声明的数据数组变量。

您需要执行以下操作。

  string serverVariable = "abc";
        string script = string.Format("javascript:var j={0};", serverVariable);        
        ScriptManager.RegisterStartupScript(this, this.GetType(), "uniqueKey", script, true);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM