如何在浏览asp.net页面时保持控件状态

时间:2022-05-19 21:08:16

When we use asp.net pages we can navigate from one page to another via more than one method.

当我们使用asp.net页面时,我们可以通过多种方法从一个页面导航到另一个页面。

This issue becomes more comlicated when you want to keep the history of current user navigation.

当您想要保留当前用户导航的历史记录时,此问题会变得更加复杂。

Lets say we have a form. The user will start to fill it, by adding values to one or more fields, but on my case he can create a navigation to another page before we posting-back the current page and thats ofcourse couses the controls to loose its values.

让我们说我们有一个表格。用户将通过向一个或多个字段添加值来开始填充它,但在我的情况下,他可以在我们回发当前页面之前创建到另一页面的导航,并且那些可以使控件放松其值。

How can i keep the controls states through postbacks between asp.net pages.

如何通过asp.net页面之间的回发来保持控件状态。

Should i use the SessionState or maybe cache it for each user?

我应该使用SessionState还是为每个用户缓存它?

thanx

3 个解决方案

#1


You pretty much have the choice of session state, cookies, or home grown state maintenance using a database. I typically get around this by combining all my pages into separate panels within a single .aspx. That way I can use object persistence and viewstate. Rather than navigating from page to page, I merely have to toggle the .visible property of different panels depending on my users' navigation choices.

您几乎可以使用数据库选择会话状态,cookie或本地状态维护。我通常通过将所有页面组合到单个.aspx中的单独面板中来解决这个问题。这样我就可以使用对象持久性和viewstate。我只需根据用户的导航选择切换不同面板的.visible属性,而不是从一个页面导航到另一个页面。

RO

#2


The answer mostly different in different application types. For example if you plan that your application will have a lot of people storing in session become an expensive operation, but for small applications it work good. In all cases you can create some mechanism that will store temporary entered data into database, this approach will work everywhere, but it's slowly than in memory cache. To give correct advice please explain a bit more about your application.

答案在不同的应用程序类型中大多不同。例如,如果您计划您的应用程序将有很多人在会话中存储变得昂贵的操作,但对于小型应用程序,它工作得很好。在所有情况下,您都可以创建一些将临时输入的数据存储到数据库中的机制,这种方法可以在任何地方使用,但它比内存缓存慢。要提供正确的建议,请详细说明您的申请。

#3


You could use Session variables or the ASP.NET Cache object to store state so that the user can resume filling in the form after navigating away from the page. However, if the issue is that the data entry is a lengthy process that the user may wish to pause and resume at a later time, give them the option to save their current progress to a database. If the user attempts to navigate away from the page, remind them that they may lose their current work and give them the option to save it.

您可以使用Session变量或ASP.NET Cache对象来存储状态,以便用户可以在离开页面后继续填写表单。但是,如果问题是数据输入是一个漫长的过程,用户可能希望稍后暂停和恢复,请为他们提供将当前进度保存到数据库的选项。如果用户尝试离开页面,请提醒他们可能会丢失当前的工作并为他们提供保存选项。

#1


You pretty much have the choice of session state, cookies, or home grown state maintenance using a database. I typically get around this by combining all my pages into separate panels within a single .aspx. That way I can use object persistence and viewstate. Rather than navigating from page to page, I merely have to toggle the .visible property of different panels depending on my users' navigation choices.

您几乎可以使用数据库选择会话状态,cookie或本地状态维护。我通常通过将所有页面组合到单个.aspx中的单独面板中来解决这个问题。这样我就可以使用对象持久性和viewstate。我只需根据用户的导航选择切换不同面板的.visible属性,而不是从一个页面导航到另一个页面。

RO

#2


The answer mostly different in different application types. For example if you plan that your application will have a lot of people storing in session become an expensive operation, but for small applications it work good. In all cases you can create some mechanism that will store temporary entered data into database, this approach will work everywhere, but it's slowly than in memory cache. To give correct advice please explain a bit more about your application.

答案在不同的应用程序类型中大多不同。例如,如果您计划您的应用程序将有很多人在会话中存储变得昂贵的操作,但对于小型应用程序,它工作得很好。在所有情况下,您都可以创建一些将临时输入的数据存储到数据库中的机制,这种方法可以在任何地方使用,但它比内存缓存慢。要提供正确的建议,请详细说明您的申请。

#3


You could use Session variables or the ASP.NET Cache object to store state so that the user can resume filling in the form after navigating away from the page. However, if the issue is that the data entry is a lengthy process that the user may wish to pause and resume at a later time, give them the option to save their current progress to a database. If the user attempts to navigate away from the page, remind them that they may lose their current work and give them the option to save it.

您可以使用Session变量或ASP.NET Cache对象来存储状态,以便用户可以在离开页面后继续填写表单。但是,如果问题是数据输入是一个漫长的过程,用户可能希望稍后暂停和恢复,请为他们提供将当前进度保存到数据库的选项。如果用户尝试离开页面,请提醒他们可能会丢失当前的工作并为他们提供保存选项。