gpt4 book ai didi

c# - Timer Tick 不增加时间间隔的值

转载 作者:太空狗 更新时间:2023-10-29 20:15:44 27 4
gpt4 key购买 nike

我想增加计时器滴答事件的值,但它没有增加不知道我忘记了什么它只显示 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的值。

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;
}

关于c# - Timer Tick 不增加时间间隔的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53151925/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com