Last post Mar 23, 2007 11:53 PM by mwisebaker
Mar 23, 2007 04:28 PM|mwisebaker|LINK
Is there a way for variables to retain their values across postbacks on the same page? My code looks like this:
<script language="VB" runat="server">
Dim intLastStepCompleted As Integer
Sub Page_Load(Sender As Object, E As EventArgs)
I have several data validation steps behind the Page_Load sub, and I use the variable "intLastStepCompleted" to keep track of how far the user has gotten. However, it doesn't seem to retain its value after each time the user submits the form.
I know I could use session variables, but I'm trying to get away from over-utilization of them, especially since I don't need to use the variable on any other pages.
Mar 23, 2007 05:11 PM|augustwind|LINK
Mar 23, 2007 08:08 PM|mwisebaker|LINK
Check out 'Viewstate'
Thanks, that seems to do what I need.
Some of the info says that overuse of ViewState could have a negative effect on performance. Unfortunately I couldn't find anything that says how much data is too much. I'm storing about 25 fields' worth of data, all strings, using this method. Would that
pose a problem with multiple simultaneous users?
Mar 23, 2007 08:30 PM|aspwhiz|LINK
Mar 23, 2007 11:53 PM|mwisebaker|LINK
Why do you need to save 25 fields? You said you have a variable intLastStepCompleted. I would think that is the only value you should have to store in the viewstate. If you are not doing anything different and simply showing your form again, the values should
already be filled out. They should be ready for you to use at whatever step you left off on for validation.
Sorry for the confusion. I was using that as merely an example. The way the code works is this (it's for a hotel reservation page):
1) Collect data from user (25 inputs). Store user data in variables (or the ViewState)
2) Validate user input for completeness, etc. If fail, go back to step 1. If pass, hide user form and display a recap of the user's entries.
3) Recap page has a "Submit Reservation" button. Once user clicks that button, insert a new record into a database using the 25 variables collected in step 1.
This is all being done on one page using PostBacks. The problem that precipitated this question is the fact that when I store the user inputs into variables in step 1, those variables lose their values after each PostBack, so I can't use them to feed my
SQL statement for step 3.
I hope that better explains the context of my question.