Button click event doesn't work properly

前端 未结 4 789
梦如初夏
梦如初夏 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:23

    You only need to change the way you increase the counter in the method. You are not saving it back as a new variable after the button click.

    int counter = 0;     
    protected void btnCompTagUpdate_Click(object sender, EventArgs e) {     
    if (counter == 0)     { 
    counter = counter + 1;        
    label1.Text="First Time";             
    }    
     else if (counter == 1) {         
    counter = counter - 1;        
    label1.Text="Second Time";   
     }     
     } 
    

提交回复
热议问题