| | |
ASP.Net timer control
Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Feb 2006
Posts: 2
Reputation:
Solved Threads: 0
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!!!!
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!!!!
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
but ive seen this done with ajax. like using
setTimeout() to loop and XMLHttpRequest to do the postback
magicajax.net makes it easy
•
•
Join Date: Jun 2006
Posts: 5
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jun 2006
Posts: 5
Reputation:
Solved Threads: 0
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
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
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
•
•
Join Date: Mar 2009
Posts: 1
Reputation:
Solved Threads: 0
The timer can be used in ASP.NET page as follows:
ASP.NET Syntax (Toggle Plain Text)
protected System.Timers.Timer _timer; protected void Page_Init(object sender, EventArgs e) { // initialize the time control _timer = new System.Timers.Timer(5000); // subscribe to the Elapsed event _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) { // Do whatever you want to do on each tick of the timer }
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.
![]() |
Similar Threads
- Simple ASP.Net Login Page using C# (C#)
- How To Hyperlink Normal HTML page with ASP.NET Page? (ASP.NET)
- ASP.NET Timer Button (ASP.NET)
- ASP in ASP.NET application (ASP.NET)
- ASP.NET / C# Dynamic Control (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: ASP.Net
- Next Thread: convert string to object type
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol ajax alltypeofvideos asp asp.net bc30451 beginner bottomasp.net browser businesslogiclayer c# c#gridviewcolumn cac checkbox class commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv formatdecimal forms formview gridview gudi homeedition iis javascript jquery listbox menu microsoft mouse mssql nameisnotdeclared news opera panelmasterpagebuttoncontrols problem redirect registration relationaldatabases reportemail schoolproject security serializesmo.table sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webdevelopment webprogramming webservice youareanotmemberofthedebuggerusers





