How To Refresh Time
i have a date time control where i have provided format as TIME...it shows me the current time when the form is loaded....but it stays constant(i.e it shows the constant time when the page was loaded)..i need the time to get refreshed for every 5 secs.
Plzz Help...

Kirtan PatelRank #292 · 8.6K reputationPosted Oct 12, 2009, 2:47 AM EDT
you need to Use Update panel and Timer Control of Ajax to Achieve this :)
Rajeswari nathan97 reputationPosted Oct 12, 2009, 2:47 AM EDT
If you dont want to refresh the page. use the call the IFRAME to get the current time using the Settimeout..
I thing you catch my point...
function DisplayTime(){
document.getElementById('DisplayTimeLable').value = "Current Datetime"
setTimeout("DisplayTime()",5000)
}
DisplayTime()
Abhi Joz13 reputationPosted Oct 12, 2009, 3:12 AM EDT
Roei BarRank #1,271 · 1.4K reputationPosted Oct 12, 2009, 3:20 AM EDT
Add a timer
set the timer.Elapsed event
on timer.Elapsed set the text of the control once again to DateTimeNow
and thats it
Rajeswari nathan97 reputationPosted Oct 12, 2009, 3:34 AM EDT
just drag and use the Timer control..
in the timer event you can change the current time..
give the 5Sec interval for that Timer..
See the following code
private void Form1_Load(object sender, EventArgs e)
{
Timer MyTimer = new Timer();
MyTimer.Interval = 1000;
MyTimer.Enabled = true;
MyTimer.start()
}
public void MyTimer_Tick(Object Sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
}
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 12, 2009, 3:55 AM EDT
private void Form1_Load(object sender, EventArgs e)
{
Timer t1 = new Timer();
t1.Interval = 1000;
t1.Tick +=new EventHandler(t1_Tick);
t1.Enabled = true;
}
public void t1_Tick(Object Sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
}
manohar vakkala66 reputationPosted Oct 12, 2009, 4:40 AM EDT
Master BillaRank #2,229 · 630 reputationPosted Oct 12, 2009, 9:03 AM EDT
Here is complete code for you
private void StartTime()
{
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Tick += new EventHandler(timer_Tick);
timer.Enabled = true;
timer.Interval = 5000; // 5 seconds
}
void timer_Tick(object sender, EventArgs e)
{
// here every 5 sonds tick event will raise
}
Just copy and paste in your class file
Thank you