What should I use开发者_如何学JAVA 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 .
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
Store the value in session state:
int someValue = 123;
Session["SomeValue"] = someValue;
To retrieve it:
someValue = (int)Session["SomeValue"];
精彩评论