Timers.Timer to create StopWatch. I use Timer.Elapsed to handle event that display time after perticular time. I give timer interval of 1 and enabled to true. I also make AutoReset to true. But the problem is event is firing only once.and I get time in Textbox only once.How can I change Time in TextBox Every Second.I try all alternatives but not get success…Thank You
System.Timers.Timer StopWatchTimer = new System.Timers.Timer();
Stopwatch sw = new Stopwatch();
public void StopwatchStartBtn_Click(object sender, ImageClickEventArgs e)
{
StopWatchTimer.Start();
StopWatchTimer.Interval = 1;
StopWatchTimer.Enabled = true;
StopWatchTimer.AutoReset =true;
sw.Start();
StopWatchTimer.Elapsed += new System.Timers.ElapsedEventHandler(StopWatchTimer_Tick);
}
protected void StopWatchStopBtn_Click(object sender, ImageClickEventArgs e)
{
TextBoxStopWatch.Text = "00:00:000";
StopWatchTimer.Stop();
sw.Reset();
sw.Stop();
}
public void StopWatchTimer_Tick(object sender,EventArgs e)
{
TextBoxStopWatch.Text= Convert.ToString(sw.Elapsed);
}
UPDATE:
I try it by creating new website in Visual Studio.But still don’t get success.same problem . Now update is when I set Break Point in Line
TextBoxStopWatch.Text= Convert.ToString(sw.Elapsed);
Text is Continuously changing there but not displaying in TextBox. Hope You can Understand this.
You can’t do it this way in a web page.
By the time the page is rendered, the server is done and the client has disconnected. It’s not going to get any more updates from your timer.
If you need to have a timer on the page itself showing some changing numbers then you will have to do this via javascript.