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...
Master BillaPosted Oct 12, 2009, 1:03 PM
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
manohar vakkalaPosted Oct 12, 2009, 8:40 AM
Kirtan PatelPosted Oct 12, 2009, 7:55 AM
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();
}
Rajeswari nathanPosted Oct 12, 2009, 7:34 AM
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();
}
Roei BarPosted Oct 12, 2009, 7:20 AM
Add a timer
set the timer.Elapsed event
on timer.Elapsed set the text of the control once again to DateTimeNow
and thats it
Abhi JozPosted Oct 12, 2009, 7:12 AM
Rajeswari nathanPosted Oct 12, 2009, 6:47 AM
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()
Kirtan PatelPosted Oct 12, 2009, 6:47 AM
you need to Use Update panel and Timer Control of Ajax to Achieve this :)