Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to save variables between postbacks asp.net?

Tags:

c#

.net

asp.net

How can I save variables in asp.net between postback? I'm using HttpContext.Current.Items but it always disposes after postback is there any other option to do that?

like image 444
Endiss Avatar asked Apr 13 '12 09:04

Endiss


People also ask

How can we store values between Postbacks in asp net?

if your variable is serializable, and you can live with the client reading its value, and it should only live during the postbacks sequence in the scope of the page => you should use ViewState. Show activity on this post.

What is ViewState in asp net c#?

View state is the method that the ASP.NET page framework uses to preserve page and control values between round trips. When the HTML markup for the page is rendered, the current state of the page and values that must be retained during postback are serialized into base64-encoded strings.


1 Answers

If your variable is not serializable or you do not want the client to be able to read its value => use inProc Session

If your variable is serializable and you do not want the client to be able to read its value => use database Session

if your variable is serializable, and you can live with the client reading its value, and it should only live during the postbacks sequence in the scope of the page => you should use ViewState.

like image 133
jbl Avatar answered Sep 28 '22 03:09

jbl