Roobah
Roobah

Reputation: 321

storing value in a page across postbacks

What should I use to store a vlaue that is used by a number of methods of the same page ? It will not be used in other pages but will be used across postbacks . Do I use static variable or session or hiddenfield or something else ?

Thanks a lot .

Upvotes: 0

Views: 1233

Answers (2)

VikciaR
VikciaR

Reputation: 3412

It's up to You to decide which way is best for you: viewstate, hidden field, session, database record and etc. For your question looks that best answer: viewstate.

  • ViewState - simple, relatively low security (user can modify, but it's difficult if you use validation), uses network traffic
  • hidden field - simple, low security (user can modify), uses network traffic
  • Session - simple, high security, you must think how dispose value later (if you revisit page and don't need that value take effect)
  • Database - relatively difficult, secure

Upvotes: 5

IrishChieftain
IrishChieftain

Reputation: 15253

Store the value in session state:

int someValue = 123;
Session["SomeValue"] = someValue;

To retrieve it:

someValue = (int)Session["SomeValue"];

Upvotes: 0

Related Questions