Click here to Skip to main content
15,898,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to create countdown timer in minutes and seconds. ( like: 20:53)
this time decrease.like this -20:52,20:51,20:50....
how to create this timer.

i have create timer,but it is displaying only seconds.
my code is here.
<asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick" >
   </asp:Timer>


protected void Timer1_Tick(object sender, EventArgs e)
        {
            int seconds;
            if (Convert.ToString(Lable2.Text) != "")
            {
                seconds = int.Parse(Lable2.Text);
            }
            else
            {
                seconds = Convert.ToInt32(60);//set some time count in default timer

            }
            Session["timeoutSecond"] = (seconds - 1).ToString();
            if (seconds > 0)
            {

                Lable2.Text = (seconds - 1).ToString();

            }
            else
            {
                //Timer1.Enabled = false;
                

            }

        }


i have to start and stop the timer ,when ever I want.
how to do this also.
Posted
Updated 21-Apr-13 22:34pm
v3
Comments
StianSandberg 22-Apr-13 4:48am    
A server side script is not a good solution here. You should use javascript to achieve this. Search for javascript countdown at google and you'll find hundreds of good alternatives.

I'd suggest you to use a JavaScript timer:
http://www.w3schools.com/js/js_timing.asp[^]
You can create a perfect countdown out of it:
http://www.proglogic.com/code/javascript/time/countdown.php[^].

Hope I was able to help you!
cheers,
Marco
 
Share this answer
 
If you have total remaining seconds, say tot_seconds, then
C#
int seconds = tot_seconds % 60;
int minutes = tot_seconds / 60;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900