Mikayil Abdullayev
Mikayil Abdullayev

Reputation: 12367

Is it fine to use Viewstate when there are plenty of variables to store

I know the differences between SessionState and ViewState:

  1. SessionState persists for the whole session where as ViewState is for one the same page.
  2. SesssionState stays in the server but VewState travels between client and server

Now taking the above into account, if I have plenty of variables(which means that much bandwidth) that I need to keep through postbacks which one should I pick? I stuck in the middle because:

  1. I know that I'm going to use those variables only in one page and ViewState is appropriate for this case
  2. On the other, it seems it's going to take much bandwidth as the variables are quite a few.

Upvotes: 0

Views: 79

Answers (2)

nunespascal
nunespascal

Reputation: 17724

Unless you are speaking of a few thousand variables, there is nothing to worry about.
Most asp.net controls store a lot of their state variables in the ViewState.

You can easily use a page performance tool to see the increase in your page size after you put the variables in ViewState. In most cases it is not something to worry about.

Upvotes: 1

Adil
Adil

Reputation: 148110

Variables usually do not take much space would be in kbs or even less, putting data in session un-necessarily could degrade the performance of server as the number of clients increase the load on server machine is multiplied. On the other hand view state does not hold space on server and could save memory for other useful operations.

Upvotes: 1

Related Questions