Home
Manage Your Code
Snippet: Cookie Parameter For DataSource (C#)
Title: Cookie Parameter For DataSource Language: C#
Description: This is a custom parameter for a cookie value Views: 398
Author: Kevin Isom Date Added: 11/20/2007
Copy Code  
1[ToolboxData("<{0}:CookieParameter ></{0}:CookieParameter>")]
2
3    [System.Drawing.ToolboxBitmap(typeof(Parameter))]
4
5    public class CookieParameter : Parameter
6
7    {
8
9        private string _cookieKey;
10
11        public string Key
12
13        {
14
15            get { return _cookieKey; }
16
17            set { _cookieKey = value; }
18
19        }
20
21        private string _cookie;
22
23        public string Cookie
24
25        {
26
27            get { return _cookie; }
28
29            set { _cookie = value; }
30
31        }   
32
33        public CookieParameter() : base()
34
35        {
36
37        }
38
39        public CookieParameter(string name, object value) : base(name)
40
41        {
42
43        }
44
45        public CookieParameter(string name, TypeCode type, object value) : base(name, type)
46
47        {
48
49        }
50
51        protected CookieParameter(CookieParameter original)
52
53            : base(original)
54
55        {
56
57        }
58
59        protected override object Evaluate(HttpContext context, Control control)
60
61        {
62
63            if ((context != null) && (context.Session != null))
64
65            {
66
67                return context .Request.Cookies[Cookie].Values.Get(Key);
68
69            }
70
71            return null;
72
73        }
74
75        protected override Parameter Clone()
76
77        {
78
79            return new CookieParameter(this);
80
81        }
82
83    } 
Usage