如何从页面开始执行timercountdown以继续其他页面? [英] how can I do timercountdown start from a page to continue another page?
本文介绍了如何从页面开始执行timercountdown以继续其他页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何进行计时器倒计时启动x.aspx页面,如果你去y.aspx页面,这个计时器继续从那里继续。
x.aspx如果你去y.aspx
10 7
9 6
8 5
4
3
2
1
0
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
推荐答案
简单。 ..
在X.aspx.cs文件中,
Simple...
In X.aspx.cs file,
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");
}
}
在Y.aspx.cs中,
In Y.aspx.cs,
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");
}
}
我将计时器间隔设置为1000.在X& Y aspxs
I set the timer interval to 1000. on both X & Y aspxs
这篇关于如何从页面开始执行timercountdown以继续其他页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文