服务器端数据在文本框中显示为null

时间:2014-04-02 11:54:58

标签: c# javascript jquery google-visualization

脚本代码:

<script type="text/javascript">
  function drawVisualization01(dataValues) {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Column Name');
    data.addColumn('number', 'Class Average ');
    data.addColumn('number', 'Score ');

    for (var i = 0; i < dataValues.length; i++) {
      data.addRow([dataValues[i].ColumnName, dataValues[i].Value1, dataValues[i].Value2]);
    }

    var options = {
      title: 'Topics Performance',
      hAxis: { title: 'Topics', titleTextStyle: { color: 'red', fontSize: 15 }, textStyle: { fontSize: 12} },
      vAxis: { format: '###.##%', textStyle: { fontSize: 12 }, maxValue: 1, minValue: 0 }
    };

    var formatter = new google.visualization.NumberFormat({ pattern: '###.##%' });
    formatter.format(data, 1);
    formatter.format(data, 2);

    var chart_div01 = document.getElementById('visualization1');
    var chart = new google.visualization.ColumnChart(chart_div01);

    // Wait for the chart to finish drawing before calling the getImageURI() method.
    google.visualization.events.addListener(chart, 'ready', function () {
      chart_div01.innerHTML = '<img src="' + chart.getImageURI() + '">';
      console.log(chart_div01.innerHTML);
      var result = Foo(document.getElementById('<%=Textbox1.ClientID%>').value);
      document.getElementById('<%=Textbox2.ClientID%>').value = chart.getImageURI();
    });
    chart.draw(data, options);
  }
  </script>

**JSON function**

<script >
  function Foo(user_id) {
    // Grab the information
    var values = user_id;
    var theIds = JSON.stringify(values);

    // Make the ajax call
    $.ajax({
      type: "POST",
      url: "ProgressReportNew.aspx/Done", // the method we are calling
      contentType: "application/json; charset=utf-8",
      data: {ids: theIds },
      dataType: "json",
      success: function (result) {
        alert('Yay! It worked!');               
      },
      error: function (result) {
        alert('Oh no :(');
      }
    });
  }
</script>

[WebMethod]
  public static void done(string ids)
  {
     String a = ids;
     HttpContext context = HttpContext.Current;
     context.Session["a"] = a;
   }

C#代码:

int t1 = Textbox1.Text.Trim().Length;             
string as1 = (string)(Session["a"]);

简短的代码,我想一键转换谷歌图表到图像。它是我的代码;从服务器端我想传递图像base64字符串,但不幸的是我没有进入文本框;我尝试使用Ajax仍然没有发生。

任何人都可以帮我解决这个问题,在我先用2个按钮转换图像和pdf工作之前,只有一个按钮不能正常工作。

0 个答案:

没有答案