Newb problem with Flag variables

  • Thread starter Thread starter Blue Man
  • Start date Start date
B

Blue Man

Hello
I want to create a link that open and close a panel. but i can't save a
variable as a flag to test each time if the panel is open or not, this is my
code :
int flag=0;
private void LinkButton1_Click(object sender, System.EventArgs e)
{
if(flag==0)
{ Panel1.Visible=true;
Panel1.Enabled=true;
flag=0; }
else{
Panel1.Visible=false;
Panel1.Enabled=false;
flag=1;
}}

the problem is Flag varibale that when ever i push the link the page reload
so the value resets to 0 again. how can i use global variables that don't
change whit refreshing page?
i know i can use database but that's not the way to solve on such a simple
page. i also tried Session but it has the same problem, resets whenever
page refresh(or link gets click).

Thanks
 
Hi,
you can check for state of Panel1.Visible or you can just
add in LinkButton1_Click following:
Panel1.Visible = !Panel1.Visible;

Best,

Svetlin Grancharov
 
About second question you can put somewhere on the page:
<input id="HiddenValue" type=hidden value="" runat=server>

and after that with code set the value with:

HiddenValue.Value = "value"

or you can read the value with

var = HiddenValue.Value

Best

Sve
 
Back
Top