Button click event doesn't work properly

前端 未结 4 787
梦如初夏
梦如初夏 2020-12-22 02:43

This following code handle button click event. When the user click first time it sets the lable as \"First Time\", and when the user click second time it sets the lable as \

4条回答
  •  我在风中等你
    2020-12-22 03:35

    void Page_Load(object sender, EventArgs e)
     {
       if (!IsPostBack)
         Session["counter"]=0;
     }
    

    You set the counter value at once, when first the page loads.

    protected void btnCompTagUpdate_Click(object sender, EventArgs e)
    {
     int counter=0;
    if (Session["counter"]!=null)
     counter= Convert.ToInt32(Session["counter"]);
      if (counter == 0)
      {
        lable1.Text="First Time";
        counter++;
       Session["counter"]=counter;
      }
     else if (counter == 1)
      {
        lable1.Text="Second Time";
        counter--;
       Session["counter"]=counter;
      }
    
    }
    

提交回复
热议问题