Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i m using this code

C#
protected void Timer1_Tick(object sender, EventArgs e)
{
    TextBox1.Text = DateTime.Now.ToLongTimeString();
}


i m using update panel.. it work fine


now i want to run loop
with in timer and show my value like counter....

how it will happen...
it direct show max value of loop...
Posted

Try google for this first.
just see the forumn
Countdown timer on ASP.NET page[^]
 
Share this answer
 
I guess you want to show Current DateTime like a Clock in TextBox. You need not to have "for loop" for this.

Try as below code. It should fullfill your requirement. It will show current DateTime in "TextBox1" after every 1 second.

protected System.Timers.Timer _timer;

protected void Page_Init(object sender, EventArgs e)
{
  _timer = new System.Timers.Timer(1000);	
  _timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
}
protected void Page_Load(object sender, EventArgs e)
{
  _timer.Start();
}

private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
 TextBox1.Text = DateTime.Now.ToLongTimeString();
}
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900