Timer Tick not increasing values on time interval

  • A+
Category:Languages

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

 


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

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: