声明会话字典母版页 [英] declaring a session dictionary in a master page

查看:119
本文介绍了声明会话字典母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何声明一个名为MyDic字典中的母版页?

How do you declare a dictionary called MyDic in the master page?

我要MyDic持有对象MyObj中带有日期为重点的列表,以便我可以这样写:从MyDic获取列表日期2011年1月28日或放MyObj中的这个名单1 / 28/2011年MyDic。

I want MyDic to hold lists of objects MyObj with a date as the key so that I can write something like this: "get the list for date 1/28/2011 from MyDic" or "put this list of MyObj from 1/28/2011 in MyDic".

我想声明字典中的母版页,这样我可以在每一个页面访问它。

I'd like to declare the dictionary in the master page so that I can access it in every page.

感谢。

推荐答案

你是如何坚持上列表规划?
相反,在母版页创造它,你可以创建它作为一个应用程序变量,或者如果它是用户特定的会话变量。在这两种情况下,你会做这样的事情:

How were you planning on persisting the list? Instead of creating it in the master page, you could create it as an application variable, or if it is user-specific as a session variable. In either case you would do something like:

Dictionary<DateTime, myObj> myList = new Dictionary<DateTime, myObj>();

那么你将它存储在某处:

Then you would store it somewhere:

Session["MyList"] = myList;

,当你需要再次访问它:

and when you need to access it again:

Dictionary<DateTime, myObj> myList = (Dictionary<DateTime, myObj>)Session["MyList"];

您可以做在母版页的宣言init或负载,甚至更好,我建议在任何会话或应用程序

You could do the declaration in the Master Page on init or on load, or even better i would suggest doing it in the global.asax file for either session or application

这篇关于声明会话字典母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆