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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retaining variable values between page submissions 2

Status
Not open for further replies.

James1981

Programmer
Nov 2, 2002
76
US
Hi,

We all know that controls like TextBoxes keep their values when you submit a form, but how do you achieve the same with variables you have created in the Page Class?

Is this possible or do I have to put them in hidden textboxes??!!

Cheers

James
 
Persisting those over postback is costly no matter which way you decide to do it:

ViewState offers a more scalable solution. The values are sent back and forth between the client and server in the viewstate hidden variable. Network traffic is your concern here. (this is how your textboxes are persisted, by the way)

Session offers a somewhat less scalable solution. The values are placed into server memory. The more in there, the slower the server runs. Server resources are your concern here.

Viewstate or some other form of serialization of the values is your best solution in nearly all cases.
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Ok so if I put the vars i wanna pass in a hidden textbox that is the best way of using viewstate? or is there a manual way of doing it?

James
 
ViewState["varName"] = value;

adds it manually. Works pretty much just like session, only variables are only available over post-backs, and not from page to page to page.
penny1.gif
penny1.gif

The answer to getting answered -- faq855-2992
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top