诸如视图状态和会话之类的东西
我遇到的问题如下:
我目前有一个自定义类,它生成按钮并将它们放置在母版页上的占位符上。
这些按钮的事件将特定值放入会话中,该值与数据库查询的值不同。本质上,这些按钮充当图表的过滤器。
创建所有按钮后,我意识到会话值在各个页面之间将保持不变,因此每次用户在打开另一个页面时进入不同的页面时,在打开的页面上选择的过滤器对于打开的新页面将保持不变。
起初,我想使用视图状态而不是会话,但后来意识到母版页和内容页不共享相同的视图状态。
目前,我正在考虑使用会话键的前缀来标识过滤器实际存在的页面。但是,如果用户希望同时打开多个页面,我不想使会话超载于多个值。
是否有任何解决方案需要在 app_code、主页面和内容页面之间共享视图状态(或存储值的其他方式)?
The problem that I am having is as follows:
I currently have a custom class that generates buttons and places them on a placeholder on a master page.
The events for these buttons put specific values into session that differs values for a database query. In essence, the buttons serve as filters for charts.
After creating all the buttons, I realized that session values will stay constant from page to page, so everytime a user enters a different page while another is open, the filters selected on the open page will remain constant for the new page that is opened.
At first, I wanted to use viewstate rather than session, but then realized that a master page and a content page do not share the same viewstate.
At the current time, I am thinking of using a prefix for the sesson key that will identify what page the filters actually exist for. However, I am not wanting to overload session with numerous values if the user wishes to have many pages open at the same time.
Any solutions that would entail a way to share viewstate (or some other way to store values) between app_code, the master, and the content page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用HttpContext.Current.Items,它是一个键值对集合,具有单个Http请求的生命周期。
Use HttpContext.Current.Items, it is a key-value pair collection with a lifetime of a single Http Request.
您是否考虑过 Context.Items ?
Have you considered Context.Items?
我们这里谈论的是多少个过滤器?将过滤器值存储在 URL 中。您见过谷歌或电子商务网站使用的一些网址吗?它们很长。我是这样做的:
How many filters are we talking here? Store the filter values in the URL. Have you seen some of the URLs that google or an ecommerce site uses? They are quite long. Here is how I do it:
我开始认为以下问题中显示的答案将会起作用:
ViewState 对象在母版页加载中丢失
通过属性公开所需的变量。
I'm starting to think the answer shown in the following question will work:
ViewState object lost in Master Page Load
Exposing the desired variables via a property.
如果数据不太长,cookies是典型的解决方案。
另一种选择是使用 Silverlight 隔离存储。 Silverlight 控件本身可能是不可见的(无 UI)。
If the data isn't too long, cookies are a typical solution.
Another option is to use Silverlight isolated storage. The Silverlight control itself could be invisible (no UI).