计时器刻度不按时间间隔增加值 [英] Timer Tick not increasing values on time interval
本文介绍了计时器刻度不按时间间隔增加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想增加计时器滴答事件的值,但没有增加,不知道我忘记了什么,它仅显示1
.
I want to increase values on timer tick event but it is not increasing don't know what I am forgetting it is showing only 1
.
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1000"></asp:Timer>
private int i = 0;
protected void Timer1_Tick(object sender, EventArgs e)
{
i++;
Label3.Text = i.ToString();
}
推荐答案
您可以使用ViewState进行存储,然后再次读取i
的值.
You can use ViewState to store and then read the value of i
again.
int i = 0;
protected void Timer1_Tick(object sender, EventArgs e)
{
//check if the viewstate with the value exists
if (ViewState["timerValue"] != null)
{
//cast the viewstate back to an int
i = (int)ViewState["timerValue"];
}
i++;
Label3.Text = i.ToString();
//store the value in the viewstate
ViewState["timerValue"] = i;
}
这篇关于计时器刻度不按时间间隔增加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文