Incrementing variables in ASP.net on button click

后端 未结 7 1775
别跟我提以往
别跟我提以往 2021-01-24 16:25

I am new to asp.net. I am creating a ASP.net website using VB.net. So here\'s my problem

Dim myCounter as Integer = 0

Protected Sub Button1_Click(ByVal sender A         


        
7条回答
  •  面向向阳花
    2021-01-24 16:59

       protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ViewState["Count"] = 0;
            }
    
        }
    
        protected void btnCount_Click(object sender, EventArgs e)
        {
    
            ViewState["Count"] = (int)(ViewState["Count"]) + 1;
            lblCount.Text = "Page Visited " +ViewState["Count"].ToString() +" times !";
            //Response.Write(ViewState["Count"].ToString());
    
        }
    

提交回复
热议问题