ASP.Net timer control

Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Feb 2006
Posts: 2
Reputation: thebookie is an unknown quantity at this point 
Solved Threads: 0
thebookie thebookie is offline Offline
Newbie Poster

ASP.Net timer control

 
0
  #1
Feb 14th, 2006
I am having a few problems with the Timer component in ASP.NET. I can get it to work in the C# part of visual studio but not in the ASP.NET.

The thing is a number will be logged into the website so each person will need to view the same timer counting down to zero. I guess this rules out putting it in the html??

This is the code in ASP.NET. The timer1_Elapsed method is not being called though all sources tell met this is how it works.




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;

}





In C# the 'timer1.enabled' method calls the 'timer1_Tick' which, as far as i know, is the same as the Elapsed method above.

Many thanks!!!!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: ASP.Net timer control

 
0
  #2
Feb 22nd, 2006
i might be wrong but i dont think you can use a timer in asp.net because inorder to change a value on the page it has to do a postback, which reloads the page each time.

but ive seen this done with ajax. like using
setTimeout() to loop and XMLHttpRequest to do the postback

magicajax.net makes it easy
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: ASP.Net timer control

 
0
  #3
Feb 22nd, 2006
the timer is doing its function i bet. But test is reset on each postback so will always be 1. for everyone to have the same function you should put test in the application cache (or store is somewhere outside of the session - maybe a db or file).
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 5
Reputation: LeProgrammeur is an unknown quantity at this point 
Solved Threads: 0
LeProgrammeur LeProgrammeur is offline Offline
Newbie Poster

Re: ASP.Net timer control

 
0
  #4
Jul 9th, 2006
Hello my friend!

The timer control does not work with asp.net because web application is stateless. In order to simulate a timer in asp.net you need to use javascript.

I created a control that I call it KYNOUAJAXContainer that basically can be used as a timer. For example, if you want a clock on the top of the page, all you have to do is drop a Label control into this KYNOUAJAXContainer control and in the page load event set the current time to the label's text property.

I posted some tutorials at the same website where I uploaded the KYNOUAJAXContainer control. Go ahead and check it out! Logon to http://www.KYNOU.com

I hope I helped
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 5
Reputation: LeProgrammeur is an unknown quantity at this point 
Solved Threads: 0
LeProgrammeur LeProgrammeur is offline Offline
Newbie Poster

Re: ASP.Net timer control

 
0
  #5
Jul 9th, 2006
Hi!
I created a control that I named KYNOUAJAXContainer that can be found at http://www.kynou.com/KYNOUControls/KYNOUControls.zip. This control allows you to add regular ASP.NET controls into it and they all become AJAX enabled. You can use this container control as a sort of timer control for ASP.NET. This is because the container control has a property called ShouldRefresh. When this property is set to true, it will refresh the content of all the controls inside of the container every RefreshInterval seconds (RefreshInterval is another property of the container control).
I posted tutorials that will walk you through the steps to use the control at http://www.KYNOU.com under the Tutorial Index => Ajax => KYNOU AJAX Controls link
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 14
Reputation: ebookfinder is an unknown quantity at this point 
Solved Threads: 1
ebookfinder ebookfinder is offline Offline
Newbie Poster

Re: ASP.Net timer control

 
0
  #6
Jul 5th, 2007
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.
Hope this help.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 2
Reputation: girigdk is an unknown quantity at this point 
Solved Threads: 1
girigdk's Avatar
girigdk girigdk is offline Offline
Newbie Poster

Re: ASP.Net timer control

 
0
  #7
May 10th, 2008
Originally Posted by ebookfinder View Post
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.
Hope this help.
I have done as it is as you provided..........downloaded kynoucontrols,added to the ttol box and then in page load I added the code to display time........but it not running..........any idea
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 1
Reputation: dattadeb is an unknown quantity at this point 
Solved Threads: 0
dattadeb dattadeb is offline Offline
Newbie Poster

Re: ASP.Net timer control

 
0
  #8
Mar 6th, 2009
The timer can be used in ASP.NET page as follows:

  1. protected System.Timers.Timer _timer;
  2. protected void Page_Init(object sender, EventArgs e)
  3. {
  4. // initialize the time control
  5. _timer = new System.Timers.Timer(5000);
  6.  
  7. // subscribe to the Elapsed event
  8. _timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
  9. }
  10.  
  11. protected void Page_Load(object sender, EventArgs e)
  12. {
  13. _timer.Start();
  14. }
  15.  
  16. private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  17. {
  18. // Do whatever you want to do on each tick of the timer
  19. }
Last edited by peter_budo; Mar 8th, 2009 at 6:12 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 1
Reputation: herrturtur is an unknown quantity at this point 
Solved Threads: 0
herrturtur herrturtur is offline Offline
Newbie Poster

Re: ASP.Net timer control

 
0
  #9
Sep 21st, 2009
Try the Timer1_Tick event.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC