Use Timer Contorl in asp.net
-
how use Timer Control in asp.net
-
how use Timer Control in asp.net
-
how use Timer Control in asp.net
Timer controls work well on an asp.net page. As a web page refreshes each time it is back, You should declare the time control as a static attribute of the page, as well as the timer event handler.
protected System.Timers.Timer timer1; private int test; protected void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here test = 1; timer1.Interval = 1000; timer1.Start(); timer1.Enabled = true; } private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { test = test+1; lblCounter.Text = "count:"+test; }
SSK. Anyone who says sunshine brings happiness has never danced in the rain.
-
i was try but not work. please give me example.
-
i was try but not work. please give me example.
-
Timer controls work well on an asp.net page. As a web page refreshes each time it is back, You should declare the time control as a static attribute of the page, as well as the timer event handler.
protected System.Timers.Timer timer1; private int test; protected void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here test = 1; timer1.Interval = 1000; timer1.Start(); timer1.Enabled = true; } private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { test = test+1; lblCounter.Text = "count:"+test; }
SSK. Anyone who says sunshine brings happiness has never danced in the rain.
Vri SSK wrote:
Timer controls work well on an asp.net page.
No, they really don't. In your example every user will have the same timer :| A javascript timer will work, such as the one within the AJAX Toolkit. Please consider your answer to questions before posting them, if you're unsure its probably better to not bother posting.
-
how use Timer Control in asp.net
One problem I found on the timer control is that if I had code running on page load and the timer was set to update say eevry minute the code on the page load would run as well. This is a big drawback if you are using postback scripts etc
The answers posted by me are suggestions only and cannot be used in anyway against me.
-
Vri SSK wrote:
Timer controls work well on an asp.net page.
No, they really don't. In your example every user will have the same timer :| A javascript timer will work, such as the one within the AJAX Toolkit. Please consider your answer to questions before posting them, if you're unsure its probably better to not bother posting.
J4amieC wrote:
f you're unsure its probably better to not bother posting
I'm never 100% sure.. ..even an answer that isn't 100% can give you a pointer in the right direction. Sometimes such an answer becomes the base for an entire discussion. It does happen that we generate an adequate answer as a group, because we interact. FWIW; you can make the code user-specific :)
-
J4amieC wrote:
f you're unsure its probably better to not bother posting
I'm never 100% sure.. ..even an answer that isn't 100% can give you a pointer in the right direction. Sometimes such an answer becomes the base for an entire discussion. It does happen that we generate an adequate answer as a group, because we interact. FWIW; you can make the code user-specific :)
eddyvluggen wrote:
..even an answer that isn't 100% can give you a pointer in the right direction.
And a stupid answer like the one given can lead you down the garden path, round the block and back again. In addition, im 99% sure the OP wanted a timer on the client not the server. He may not have specified that, but after years of answering questions on forums like CP, you can generally tell.
eddyvluggen wrote:
FWIW; you can make the code user-specific
Not with a static Timer you cant. You may wish to read up on the static keyword.
-
eddyvluggen wrote:
..even an answer that isn't 100% can give you a pointer in the right direction.
And a stupid answer like the one given can lead you down the garden path, round the block and back again. In addition, im 99% sure the OP wanted a timer on the client not the server. He may not have specified that, but after years of answering questions on forums like CP, you can generally tell.
eddyvluggen wrote:
FWIW; you can make the code user-specific
Not with a static Timer you cant. You may wish to read up on the static keyword.
J4amieC wrote:
You may wish to read up on the static keyword.
Will do. I assumed that the component is simply shared among the users. Am I mistaken?
J4amieC wrote:
And a stupid answer like the one given can lead you down the garden path, round the block and back again.
Thanks for the warning :)