title: Stopwatch Timer in Asp.Net
body: <p>I wanna diplay a Stopwatch timer... using Asp.Net C#...</p>
  
  <p>I have looked through many threads and searched on Google also, but I can't find a proper code or solution.</p>
  
  <p>Most of the solutions I found were very hard to implement and some of them didn't work.</p>
  
  <p>I want to create stopwatch like below Image.</p>
  
  <p><img src="https://i.stack.imgur.com/t65tk.png" alt="enter image description here"></p>
  
  <p>By clicking on the start button it starts the watch from 00.00 in the format of HH.MM and and change the text of the button to Stop.  </p>
  
  <p>By clicking on that again it stops the watch and then saves that time in a database and also displays it in given TextBox.</p>
  
  <p>By clicking on reset it resets the time to 00.00.</p>
  
  <p>How can i do this?</p>
  
  <p>I doesn't have any idea about this, so some code is needed.</p>
  
  <p><strong>BELOW IS THE CODE AND IMAGE WHICH I TRIED IN THE WEBSITE...</strong></p>
  
  <p><img src="https://i.stack.imgur.com/y5NdO.png" alt="enter image description here"></p>
  
  <pre><code>using System;
  using System.Collections;
  using System.Configuration;
  using System.Data;
  using System.Linq;
  using System.Web;
  using System.Web.Security;
  using System.Web.UI;
  using System.Web.UI.HtmlControls;
  using System.Web.UI.WebControls;
  using System.Web.UI.WebControls.WebParts;
  using System.Xml.Linq;
  using System.Diagnostics;
  
  public partial class Default5 : System.Web.UI.Page
  {
      private Stopwatch sw = new Stopwatch();
          protected void Page_Load(object sender, EventArgs e)
          {
  
  
          }
  
          protected void Button3_Click(object sender, EventArgs e)
          {
              if (Button3.Text == "start")
              {
                  Timer1.Enabled = true;
                  sw.Start();
                  Button3.Text = "stop";
  
              }
              else
              {
                  Timer1.Enabled = false;
                  sw.Stop();
                  Button3.Text = "start";
  
                  //TextBox1.Text = Label1.Text;
              }
          }
  
          protected void Timer1_Tick(object sender, EventArgs e)
          {
              int hrs = sw.Elapsed.Hours;
              //int hrs = "1;
              int mins = sw.Elapsed.Minutes;
              int secs = sw.Elapsed.Seconds;
  
              Label1.Text = hrs + ":";
  
              if (mins &lt; 10)
                 Label1.Text += "0" + mins + ":";
              else
                  Label1.Text += mins + ":";
  
              if (secs &lt; 10)
                  Label1.Text += "0" + secs;
              else
                  Label1.Text += secs;
          }
  }
  </code></pre>
  
  <p><strong>AND THE CODE WRITTEN IN THE PROJECT (WHICH WORKS WELL) IS...</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.Diagnostics;
  
  namespace WindowsFormsApplication1
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
          private Stopwatch sw = new Stopwatch();
  
          private void button1_Click(object sender, EventArgs e)
          {
              if (button1.Text == "Start")
              {
                  timer1.Enabled = true;
                  sw.Start();
                  button1.Text = "Stop";
  
              }
              else
              {
                  timer1.Enabled = false;
                  sw.Stop();
                  button1.Text = "Start";
                  textBox1.Text = label1.Text;
              }
          }
  
          private void timer1_Tick(object sender, EventArgs e)
          {
              int hrs = sw.Elapsed.Hours, mins = sw.Elapsed.Minutes, secs = sw.Elapsed.Seconds;
  
              label1.Text = hrs + ":";
  
              if(mins &lt;10)
                  label1.Text += "0"  + mins + ":";
              else 
                  label1.Text += mins + ":";
  
              if (secs &lt; 10)
                  label1.Text += "0" + secs;
              else
                  label1.Text += secs;
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
  
          }
      }
  }
  </code></pre>
  
  <p>In both the timer interval is set at 1000.</p>
  
  <p>In the website the time is not increasing, it remains at 0:00:00... </p>