Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how can I do timer countdown start x.aspx page,if you go y.aspx page this timer continue remains from the place where.

x.aspx if you go y.aspx
10 7
9 6
8 5
4
3
2
1
0
Posted
Comments
Member-2338430 9-Feb-15 6:56am    
I dont want to use javascript and jquery

1 solution

Simple...

In X.aspx.cs file,
C#
public partial class X: System.Web.UI.Page
    {
        public static int dt = 60;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["timerCount"] != null)
                {
                    dt = Convert.ToInt32(Session["timerCount"]);
                }
            }
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            Label1.Text = dt.ToString();
            dt -= 1;
        }

//Redirect to y.aspx
        protected void Button1_Click(object sender, EventArgs e)
        {
            //Save the current count value to session.
            Session["timerCount"] = dt;
            Response.Redirect("Y.aspx");
        }
    }



In Y.aspx.cs,

C#
public partial class WebForm2 : System.Web.UI.Page
    {
        public static int dt1;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                dt1 = Convert.ToInt32(Session["timerCount"]);
            }
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            Label1.Text = dt1.ToString();
            dt1 -= 1;
        }
        //Redirect back to X.aspx
        protected void Button1_Click(object sender, EventArgs e)
        {
            Session["timerCount"] = dt1;
            Response.Redirect("X.aspx");
        }
    }


I set the timer interval to 1000. on both X & Y aspxs
 
Share this answer
 
v2
Comments
Member-2338430 9-Feb-15 8:05am    
thank you very much I want to ask another question please
public static int 60
must be 20 minutes so how can I do set a time value to timer
Member-2338430 9-Feb-15 8:06am    
if timer value zero how can stop it always count down????
Shridhar Gowda 9-Feb-15 8:34am    
in Page_load event of all .aspx pages u r using timer, add this code.
if (!Page.IsPostBack)
{
dt1 = Convert.ToInt32(Session["timerCount"]);
//Timer1.Interval=//Number representation in miliseconds
}
if (dt1 == 0)
{
Timer1.Enabled =false;//It will stop the timer
}
Member-2338430 9-Feb-15 8:38am    
thanks
Member-2338430 9-Feb-15 9:51am    
timer continue down background minus vaues -1 -2 -3 ..... how can complately stop timer

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