asp.net timer viewstate

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        int ticknum = 0;
        if (ViewState["count"] != null) {

            ticknum = (int)ViewState["count"];
        }
        ticknum++;
        if (ticknum > 10)
        {
            Timer1.Enabled = false;
        }
        else 
        {
            ViewState["count"] = ticknum;
        }
    }
    protected void Timer2_Tick(object sender, EventArgs e)
    {
        this.Label1.Text = DateTime.Now.ToString();
    }
}

  

posted @ 2016-11-07 16:44  尘梦  阅读(167)  评论(0编辑  收藏  举报