DFord
DFord

Reputation: 2358

pass C# object between aspx pages

I am creating an ASPX application that collects data from the user can creates a file based on this data. Different types of data are collected based on the type of user. Also, I have to check the database to see if there is data already in the database. I am looking for an easy way to keep track of the data while traversing between all the ASPX pages that are collecting data. I know i can pass the data in the URL and if i don't find an alternative method then i will use that.

My question is, is it possible put the data into a C# object and somehow pass the instance of that object between ASPX pages?

Upvotes: 2

Views: 1200

Answers (3)

J. Steen
J. Steen

Reputation: 15578

The simplest is to use the Session bag.

Session["FirstName"] = FirstNameTextBox.Text;
Session["LastName"] = LastNameTextBox.Text;

When retrieving an object from session state, cast it to the appropriate type.

ArrayList stockPicks = (ArrayList)Session["StockPicks"];

Here's a more exhaustive article on Session state on MSDN: http://msdn.microsoft.com/en-us/library/ms178581.aspx (from which the brief code examples are shamelessly copied)

Upvotes: 2

Fedor Hajdu
Fedor Hajdu

Reputation: 4697

You can use Session object for this.

Upvotes: 1

Icarus
Icarus

Reputation: 63966

Assuming the data is not prohibitively big, I'd put the data in Session and retrieve it from page to page.

Upvotes: 1

Related Questions