诸如视图状态和会话之类的东西

发布于 2024-08-12 02:01:54 字数 381 浏览 4 评论 0原文

我遇到的问题如下:

我目前有一个自定义类,它生成按钮并将它们放置在母版页上的占位符上。

这些按钮的事件将特定值放入会话中,该值与数据库查询的值不同。本质上,这些按钮充当图表的过滤器。

创建所有按钮后,我意识到会话值在各个页面之间将保持不变,因此每次用户在打开另一个页面时进入不同的页面时,在打开的页面上选择的过滤器对于打开的新页面将保持不变。

起初,我想使用视图状态而不是会话,但后来意识到母版页和内容页不共享相同的视图状态。

目前,我正在考虑使用会话键的前缀来标识过滤器实际存在的页面。但是,如果用户希望同时打开多个页面,我不想使会话超载于多个值。

是否有任何解决方案需要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

淡淡離愁欲言轉身 2024-08-19 02:01:54

使用HttpContext.Current.Items,它是一个键值对集合,具有单个Http请求的生命周期。

Use HttpContext.Current.Items, it is a key-value pair collection with a lifetime of a single Http Request.

倾听心声的旋律 2024-08-19 02:01:54

您是否考虑过 Context.Items

Have you considered Context.Items?

将军与妓 2024-08-19 02:01:54

我们这里谈论的是多少个过滤器?将过滤器值存储在 URL 中。您见过谷歌或电子商务网站使用的一些网址吗?它们很长。我是这样做的:

  1. 我将过滤器值存储在查询中,例如 www.chart.com?filter1=val1&filter2=val2 等。
  2. 我用户 JQuery 的查询插件 在客户端操作查询,然后使用新查询再次从服务器请求图表。
  3. 这样,我就不会丢弃会话、cookies 或类似的东西,并且如果用户想要将书签存储到特定图表或通过电子邮件发送给朋友,他们可以并且保留过滤器。

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:

  1. I store the filter values in the query like, www.chart.com?filter1=val1&filter2=val2 etc.
  2. I user JQuery's query plugin to manipulate the query on the client side, and then request the chart from the server again, using the new query.
  3. This way, I'm not junking up session, cookies, or anything like that, and if the user wants to store a bookmark to a particular chart or email it to a friend, they can and the filters are preserved.
尴尬癌患者 2024-08-19 02:01:54

我开始认为以下问题中显示的答案将会起作用:

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.

小嗷兮 2024-08-19 02:01:54

如果数据不太长,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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文