2004-06-09 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / CookieParameter.cs
1 //
2 // System.Web.UI.WebControls.CookieParameter
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@users.sourceforge.net)
6 //
7 // (C) 2003 Ben Maurer
8 //
9
10 #if NET_2_0
11 using System.Collections;
12 using System.Collections.Specialized;
13 using System.Text;
14
15 namespace System.Web.UI.WebControls {
16         public class CookieParameter : Parameter {
17
18                 public CookieParameter () : base ()
19                 {
20                 }
21
22                 protected CookieParameter (CookieParameter original) : base (original)
23                 {
24                         this.CookieName = original.CookieName;
25                 }
26                 
27                 public CookieParameter (string name, string cookieName) : base (name)
28                 {
29                         CookieName = cookieName;
30                 }
31                 
32                 public CookieParameter (string name, TypeCode type, string cookieName) : base (name, type)
33                 {
34                         CookieName = cookieName;
35                 }
36                 
37                 protected override Parameter Clone()
38                 {
39                         return new CookieParameter (this);
40                 }
41                 
42                 protected override object Evaluate (Control control)
43                 {
44                         if (control == null || control.Page == null || control.Page.Request == null)
45                                 return null;
46                         
47                         HttpCookie c = control.Page.Request.Cookies [CookieName];
48                         if (c == null)
49                                 return null;
50                         
51                         return c.Value;
52                 }
53                 
54                 public string CookieName {
55                         get {
56                                 string s = ViewState ["CookieName"] as string;
57                                 if (s != null)
58                                         return s;
59                                 
60                                 return "";
61                         }
62                         set {
63                                 if (CookieName != value) {
64                                         ViewState ["CookieName"] = value;
65                                         OnParameterChanged ();
66                                 }
67                         }
68                 }
69                 
70         
71         }
72 }
73 #endif
74