?
Solved

Storing small amount of data in ViewState

Posted on 2014-07-13
5
Medium Priority
?
193 Views
Last Modified: 2014-07-20
Hello, I have a number which is incremented, which needs to be saved and retrieved at various times on postback. Which of the three would be the best method to store the  number/integer.

1. View State
2. A hidden variable on the page.
3. Session variable.

Or can someone rank the above above methods, in regards to which method is best.
0
Comment
Question by:brgdotnet
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40193785
"Best" is a subjective term. What does "best" mean to you?
0
 
LVL 2

Author Comment

by:brgdotnet
ID: 40194365
Secure, Reliable etc...etc..
0
 
LVL 19

Accepted Solution

by:
Manoj Patil earned 920 total points
ID: 40196241
Hello,
Since the Session Variables are stored on Server side , you can store and retrieve the data easily.
The benefit of this is, you can use session on other pages too, if you want.
Just with the 2 lines of code.

To Store in Session Variable :
int number=10;
Session["Counter"]=number.ToString();


To retrieve from Session Variable :
if(Session["Counter"]!=null)
     number=Convert-ToInst32(Session["Counter"]);
0
 
LVL 2

Author Comment

by:brgdotnet
ID: 40198415
Hi, I like Session, but sometimes the data will expire. What is your opinion of using ViewState instead?
0
 
LVL 19

Assisted Solution

by:Manoj Patil
Manoj Patil earned 920 total points
ID: 40200228
You can use ViewState but if you want the value on other page, the easiest way is Session.
For session
you can increase the Timeout of Session in your configuration. So that's not the problem.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question