简体   繁体   English

在ASPX页面之间传递C#对象

[英]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. 我正在创建一个ASPX应用程序,该应用程序从用户收集数据,可以基于此数据创建文件。 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. 我正在寻找一种在所有正在收集数据的ASPX页面之间进行遍历时跟踪数据的简便方法。 I know i can pass the data in the URL and if i don't find an alternative method then i will use that. 我知道我可以在URL中传递数据,如果找不到替代方法,那么我将使用该方法。

My question is, is it possible put the data into a C# object and somehow pass the instance of that object between ASPX pages? 我的问题是,是否有可能将数据放入C#对象并以某种方式在ASPX页面之间传递该对象的实例?

The simplest is to use the Session bag. 最简单的是使用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) 这是有关MSDN上的会话状态的更详尽的文章: http : //msdn.microsoft.com/zh-cn/library/ms178581.aspx (从中无耻地复制了简短的代码示例)

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

您可以为此使用Session对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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