title: ASP .NET How Can I add a Script?
body: <p>I have an issue adding a dynamic script in ASP .NET</p>
  
  <p>I want to put the script in scriptText in ASP:ScriptManager, but when I run my app it doesn't work, somebody can help me?</p>
  
  <p>This app is for make a chart with data from a Database, everything works fine when I read the data from data base and put it in scriptText, goes excellent, but I can't see the chart, if I put the code from chartsJS.org, it works fine.</p>
  
  <p>PLZ Help!
  Forward thanks!</p>
  
  <p>I have this script</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      List&lt;object&gt; office = new List&lt;object&gt;();
      List&lt;object&gt; cantidad = new List&lt;object&gt;();
      List&lt;object&gt; labelCantidad = new List&lt;object&gt;();
      List&lt;string&gt; labels = new List&lt;string&gt;();
      DataTable tablaResultado = new DataTable();
      tablaResultado = Datos.AccesoDatos.ResumenOffice();
      if (tablaResultado.Rows.Count &gt; 0)
      {
          foreach (DataRow fila in tablaResultado.Rows)
          {
              labels.Add(fila[0].ToString());
              labelCantidad.Add(fila[1].ToString());
          }
  
  
      }
      StringBuilder sb = new StringBuilder();
      string scriptText = "";
      scriptText += "var ctx = document.getElementById(" + "resumen_office" + ").getContext('2d');";
      scriptText += "var myChart = new Chart(ctx, {";
      scriptText += "type: 'line',";
      scriptText += " data: {";
      foreach (object obj in labels)
      {
          sb.Append(string.Format("'{0}', ",obj));
      }
      scriptText += "labels: [" + sb + "]";
      scriptText += "datasets: [{";
      scriptText += "label: 'Microsoft Office',";
      StringBuilder objt = new StringBuilder();
      foreach (object obj in labelCantidad)
      {
          objt.Append(string.Format("{0}, ",Convert.ToInt32(obj)));
      }
      scriptText += "data: [" + objt + "]";
      scriptText += " backgroundColor: [";
      scriptText += "'rgba(255, 99, 132, 0.2)',";
      scriptText += "],";
      scriptText += "borderColor: [";
      scriptText += "'rgba(255,99,132,1)',";
      scriptText += "],";
      scriptText += "borderWidth: 1";
      scriptText += "}]";
      scriptText += "},";
      scriptText += "options: {";
      scriptText += "scales: {";
      scriptText += "yAxes: [{";
      scriptText += "ticks: {";
      scriptText += "beginAtZero: true";
      scriptText += "}";
      scriptText += "}]";
      scriptText += "}";
      scriptText += "}";
      scriptText += "});";
      scriptText += "&lt;/script&gt;";
      grafico.CompositeScript.Path = scriptText;
  
  }
  </code></pre>
  
  <p>This script is in tests.aspx.cs </p>
  
  <p>In tests.aspx I have this</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="tests.aspx.cs" Inherits="tests" %&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="CPH" runat="Server"&gt;
  &lt;div class="container-fluid"&gt;
  &lt;canvas id="resumen_office"&gt;&lt;/canvas&gt;
  &lt;/div&gt;
  
  &lt;asp:ScriptManager ID="grafico" runat="server"&gt;
  &lt;/asp:ScriptManager&gt;
  &lt;/asp:Content&gt;
  </code></pre>