Newb problem with Flag variables

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
 
S

Svetlin Grancharov

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
 
S

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top