Mar 20, 2016 06:56 PM|sagav|LINK
I have another question.
I created a simple empty ASP.NET Web forms project. I added one Web form (no Master page)
I added two Buttons and one label to the form. Button1.Text = "Toggle" and Button2.Text = "Test"
My code behind, in C#, is the following:
public partial class wfrmMain : System.Web.UI.Page
bool bSwitch = false;
protected void Page_Load(object sender, EventArgs e)
protected void Button1_Click(object sender, EventArgs e)
bSwitch = !bSwitch;
protected void Button2_Click(object sender, EventArgs e)
//Display value of Switch
Label1.Text = bSwitch.ToString();
Button1 just toggles the Boolean variable and Button2 displays the variable's value in a label. I added two breakpoints, the first in the Button1 click event where the variable is toggled and the second in the Button2 click event where the value of bSwitch
is assigned to the label.
When I run the project and click the Toggle button I can see that the variable is successfully toggled to True, but when I click the second button to display the value I can see that the variable's value is back to false. To me it is obvious that I am still
value to persist from when Button1 is clicked to when Button2 is clicked? Thanks! Saga