Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Persisting values between aspx pags

Status
Not open for further replies.

indyanguy

Programmer
Mar 8, 2004
7
US
Hello all,

I have a form which extends to several pages and users can go from one page to any other page. I need to persist values between pages. I understand I can do it using a Session variable but would want to know the optimum way of doing it if I have hundreds of variables to store.

Thanks!
 
I would use

Session("newKey") = yourValue

or you could use the viewstate statebag:

ViewState.Add("newKey", yourValue)


either way, just make sure to cast it to the appropriate type when retrieving it.

Hope that helps!

 
Can the ViewState object be used to persist values between different pages?

I did:

Viewstate.Add("name", txtName.Text)
Response.Redirect("WebForm1.aspx")

and in WebForm1.aspx, I tried to retrieve the value using:

Response.Write(Viewstate.Item("name"))

It did not print the value

Thanks!
 
Sorry, perhaps I should have been a little clearer. As far as I know you usually use the session object to persist data across different pages, and the viewstate to persist across page loads (from postbacks, etc).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top