Class-Level Variables in Web Form

L

Landley

Hi All,

I have declared some class-level variables in a web user control. When a
button is clicked, one of these variables is set to a specific value. The
page then does a postback and the value that I previously stored in the
variable has gone.

Is there a way to keep hold of the values of these variables without using
Session variables?

Landers
 
S

sreejith.ram

If you need to maintain a value for 1 page, ViewState can help.

add variable to viewstate ViewState.Add("myvariable",myvalue)

To access the value back during postback ViewState("myvariable")

View state stores and returns object. it will need to be casted like
below before using.

int i = (int) ViewState("myvariable");
 

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,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top