title: Get ASP.NET label's text or value in JavaScript
body: <p>I want to transfer a string of data from C# to JavaScript in ASP web forms. My approach is to set the data as a text for an ASP label in C# and then grab the label's text by ID in JS.</p>
  
  <p>C# code (ascx.cs file):</p>
  
  <pre><code>    List&lt;Event&gt; eventList;
  
      protected void Page_Load(object sender, EventArgs e)
      {
          string message = string.Empty;
          SPSite franasabank = new SPSite("http://lbshrptweb/sites/fransabank/");
          SPWeb calendar = franasabank.OpenWeb();
          SPList list = calendar.Lists["Fransabank Calendar"];
          eventList = new List&lt;Event&gt;();
          foreach (SPListItem oItem in list.Items)
          {
              // Access each item in the list...  
              DateTime startTime = (DateTime)oItem["Start Time"];
              DateTime endTime = (DateTime)oItem["End Time"];
              string status = (String)oItem["Status"];
              string title = oItem.Title;
              string description = (String)oItem["Description"];
              Event calendar_event = new Event(startTime, endTime, status, title, description);
              eventList.Add(calendar_event);
          }
          foreach (Event item in eventList)
          {
              message += item.Title + " " + item.Description + item.StartDate + "-" + item.EndDate + "-" + item.Status + "\n";
          }
  
          Label1.Text = message;
      }
  </code></pre>
  
  <p>HTML snippet showing the Label (ascx file):</p>
  
  <pre><code>&lt;div data-ng-app="Calendar"&gt;
     &lt;div data-ng-controller="CalendarController" id="mycontroller"&gt;
       &lt;div class="row " data-ng-init="Initialize()"&gt;
          &lt;asp:Label ID="Label1" runat="server" Text="Label" &gt;&lt;/asp:Label&gt;
  </code></pre>
  
  <p>JavaScript code:</p>
  
  <pre><code>&lt;script&gt;
      var a = document.getElementById('&lt;%= Label1.ClientID %&gt;');
      console.log(a);
  &lt;/script&gt;
  </code></pre>
  
  <p>I'm receiving the data as null in variable 'a'. I've tried</p>
  
  <pre><code>var a = document.getElementById('&lt;%= Label1.ClientID %&gt;').innerHTML;
  </code></pre>
  
  <p>but it is also null</p>