Last post Nov 02, 2010 11:07 AM by divya.net
Jul 17, 2008 12:27 PM|truegilly|LINK
Im about to start development on a countdown timer that will display the time left for a particular product.
<div class="prd_countdown">the format will be like this - 00:00:11.
</div>I have been watching the AJAX video tutorials so im thinking of approaching this by setting an updatePannel with a timer with a tick event every 1000ms. Inside the updatePannel i could have a label that is attached
to a C# method that contains the countdown logic
1: is this a good way forward or not.
2: can anyone suggest data time classes/methods that i will find useful so for example an admin can enter a start date and an end date and the timer will show the days, hours, minutes and seconds remaining.
the site im trying to emulate is this ... http://www.telebid.com/ looks like they have AJAX countdown timers too.
thank you for your help
Jul 21, 2008 09:04 AM|Vince Xu - MSFT|LINK
If you use Ajax Timer to achieve countdown timer, it will post request each seconds. Too frequently request to server is not a good idea and it will create much more overhead on the server.
In this way, there is a little bit time span from the real server time because it needs spend a little time to get the server time. That is acceptable if veracity is not very important in the case.
Please check the below sample:
var leave =<%=seconds %>;
var day = Math.floor(leave / ( 60 * 60 * 24))
var hour = Math.floor(leave / 3600) - (day * 24)
var minute = Math.floor(leave / 60) - (day * 24 *60) - (hour * 60)
var second = Math.floor(leave) - (day * 24 *60*60) - (hour * 60 * 60) - (minute*60)
hour=hour<10 ? "0" + hour : hour;
minute=minute<10 ? "0" + minute : minute;
second=second<10 ? "0" + second : second;
var remain=day + " days "+hour + ":"+minute+":"+second;
</script> pre <>
public double seconds;
protected void Page_Load(object sender, EventArgs e)
seconds = (GetEndTime() - GetStartTime()).TotalSeconds;
private DateTime GetStartTime()
private DateTime GetEndTime()
return new DateTime(2008, 7, 23, 8, 10, 0);
Sep 21, 2008 01:40 PM|joec0814|LINK
Excellent code - works great for me - I had a more complex js routine in place and this is much better. For some reason Firefox is not updating the timelabel innerText. I have the exact code above. Anyone have an idea as to why? Thanks!
Sep 21, 2008 03:10 PM|joec0814|LINK
Jul 12, 2009 02:55 AM|TheShinichi|LINK
Thanks for your code. I test it on IE and it work fine. However when I run the code above on FireFox (3.5), nothing appeared ! How I can fix it ?
Aug 06, 2009 02:08 PM|akviby|LINK
I still want an ajax call to check on telebid products once a second, I believe this ain't so dangerous as long as there are less than a couple of hundreds viewing the page. So I want to see some sample code when you create a timer using the ScriptManager
and the Timer objects in ASP.NET and C#.
I have a product and the startdate and starttime for the auction and a enddate and a endtime when the auction is supposed to end. I want to display in an updatepanel the days, hours, minutes and seconds left on this particular auction.
Can anyone find this sample for me?
asp.net 2.0 ajax
Nov 02, 2010 11:07 AM|divya.net|LINK
Hi Its working fine on normal Page .But when i put <div id="timelabel"></div> inside an Datalist Its notworking.
Could u tel me please how to access a control inside gridview using the same functions
Thanks in advance