title: Showing timer from c# on html page using javascript
body: <p>Hello I am trying to implement a timer in c sharp that counts seconds and display it on my html page. But when i pass the variable to javascript it is always 0. I have searched everywhere for an answer.</p>
  
  <p>This is my code so far:</p>
  
  <p>The timer object:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Timers;
  
  /// &lt;summary&gt;
  /// Summary description for Class1
  /// &lt;/summary&gt;
  public class TimerEu
  {
  
      private Timer t;
      private int time;
  
      public TimerEu()
      {
          this.t = new Timer(1000);
          this.time = 0;
  
          t.Elapsed += new ElapsedEventHandler(RunEvent);
          t.Interval = 1000;
          t.Enabled = true;
      }
  
      public void RunEvent(object source, ElapsedEventArgs e)
      {
          this.time++;
          Console.WriteLine(time);
      }
      public int getTime()
      {
          return this.time;
      }
  }
  </code></pre>
  
  <p>aspx.cs page:</p>
  
  <pre><code>public partial class _Default : System.Web.UI.Page
  {
      public String[] var=new String[10];
      public TimerEu time;
      public int  testint;
  
      protected void Page_Load(object sender, EventArgs e)
      {
          time = new TimerEu();
          testint = 0;
  
          Console.Write("hello"+time.getTime());
          for (int i = 0; i &lt; 10; i++)
              var[i] =Operations.test.convertString();
      }
  
      public void plus()
      {
          this.testint++;   
      }
  }
  </code></pre>
  
  <p>and the html/javascript part:</p>
  
  <pre><code>&lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;br&gt;&lt;/br&gt;
          &lt;br&gt;&lt;/br&gt;
          &lt;br&gt;&lt;/br&gt;
          &lt;p id="demo" runat="server"&gt;&lt;/p&gt;
  
          &lt;script&gt;
              var now=0;
  
              var x= setInterval(function () {
              //now++;
  
              now = &lt;%=time.getTime()%&gt;
          //    now =&lt;%=testint%&gt;
           //   &lt;%plus();%&gt;
  
              document.getElementById("demo").innerHTML = now;
      },1000)
  &lt;/script&gt;
  </code></pre>
  
  <p>The problem is that the javascript dosen't seem to call the getTime function every sec, instead it only gets 0 as output. What am I doing wrong?</p>