简体   繁体   中英

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?

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)

假设数据不是很大,我将数据放入Session并逐页检索。

您可以为此使用Session对象。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM