Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
m Using the timer for the exam module and facing the problem my timer is showing just the seconds no with the remaining minutes with seconds plz help me to solve this my code is like this for timer

C#
protected void Timer1_Tick(object sender, EventArgs e)
   {
       if (Session["timeout"] != null)
       {
           if (0 > DateTime.Compare(DateTime.Now, DateTime.Parse(Session["timeout"].ToString())))
           {
               Label6.Text = "seconds left : " + ((Int32)DateTime.Parse(Session["timeout"].ToString()).Subtract(DateTime.Now).TotalSeconds).ToString();
           }
           else
           {
               this.Button5_Click(sender, e);
           }
       }
   }
Posted
Updated 20-Mar-14 0:41am
v3
Comments
BillWoodruff 20-Mar-14 3:09am    
Is this ASP.NET ? Windows Forms ?

Session["timeout"] : what is this ... a Dictionary<string,DateTime> ?

What type of Timer are you using ?
durgesh j 20-Mar-14 3:17am    
this is the session where i collect the value for the timer if timeout==0 then this.buttonclick event will be called to submit the test
BillWoodruff 20-Mar-14 6:27am    
I respond to people who answer direct questions.
durgesh j 20-Mar-14 6:41am    
protected void Timer1_Tick(object sender, EventArgs e)
{
if (Session["timeout"] != null)
{
if (0 > DateTime.Compare(DateTime.Now, DateTime.Parse(Session["timeout"].ToString())))
{
Label6.Text = "seconds left : " + ((Int32)DateTime.Parse(Session["timeout"].ToString()).Subtract(DateTime.Now).TotalSeconds).ToString();
//.TotalSeconds).ToString();
}
else
{
this.Button5_Click(sender, e);
}
}
}
durgesh j 20-Mar-14 6:42am    
this is the code i have developed m new in development so cant get ur question plz help me out

1 solution

Hi,
C#
DateTime TimeLimit = DateTime.Parse(Session["timeout"].ToString());
DateTime ElapsedTime = DateTime.Now;
TimeSpan CountDownTime = TimeLimit.Subtract(ElapsedTime);

Label6.Text = CountDownTime.Minutes.ToString("00") + ":" + CountDownTime.Seconds.ToString("00");

Happy Coding!
:)
 
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