Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7489011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:11:18+00:00 2026-05-29T15:11:18+00:00

I wanna diplay a Stopwatch timer… using Asp.Net C#… I have looked through many

  • 0

I wanna diplay a Stopwatch timer… using Asp.Net C#…

I have looked through many threads and searched on Google also, but I can’t find a proper code or solution.

Most of the solutions I found were very hard to implement and some of them didn’t work.

I want to create stopwatch like below Image.

enter image description here

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.

By clicking on that again it stops the watch and then saves that time in a database and also displays it in given TextBox.

By clicking on reset it resets the time to 00.00.

How can i do this?

I doesn’t have any idea about this, so some code is needed.

BELOW IS THE CODE AND IMAGE WHICH I TRIED IN THE WEBSITE…

enter image description here

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 < 10)
               Label1.Text += "0" + mins + ":";
            else
                Label1.Text += mins + ":";

            if (secs < 10)
                Label1.Text += "0" + secs;
            else
                Label1.Text += secs;
        }
}

AND THE CODE WRITTEN IN THE PROJECT (WHICH WORKS WELL) IS…

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 <10)
                label1.Text += "0"  + mins + ":";
            else 
                label1.Text += mins + ":";

            if (secs < 10)
                label1.Text += "0" + secs;
            else
                label1.Text += secs;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

In both the timer interval is set at 1000.

In the website the time is not increasing, it remains at 0:00:00…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:11:18+00:00Added an answer on May 29, 2026 at 3:11 pm

    There is a big difference in developing for desktop and for web applications.

    In your WinForm app, the app is running on one pc, in one process. The code behind has constant access to the User Interface and can update the current time.

    In a Web application, everything is different. The web is by it’s very nature a disconnected, stateless environment. This means that the server gets a request from a browser somewhere in the world, creates a response and sends this back to the browser and forgets about it.

    This means that there is no permanent connection between the user interface showing in the browser and the code running on your on server. This is why your code is not working.

    ASP.NET WebForms has functionality that helps you with the problems that are inherent to web development, it kinds of tricks in you believing there is some permanent connection.

    I would suggest, to get better understand how things work, to remove the timer from your code behind and add a button that when clicked will change the label text.

    To really create a stopwatch you need code that runs in the browser of your users, instead of on the server. Code running in the browser knows about the environment and user interface and it can update things accordingly. This is done in a different programming language called JavaScript.

    I would suggest starting with the tutorials here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Google Sitebricks for developing a user interface. I have a table
I wanna get the Timedate value from another page using request.querystring and then use
I wanna add server controls by using javascript. The main purpose of why I
I am using UIWebView to display pdf. I wanna handle touch events on webview.
INTRO: I created a java application using JFrame. I have a JMenuBar at the
I Have a data template that i use in items control, i wanna know
I have created a drop down menu with animals. But what I wanna do
I have many images to display and do paint on them. I want to
I just wanna ask best practice supposed I have three tables. posts, categories, post_Categories.
I'm using MVC3 with razor and I wanna make a registration form where I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.