Add a more functional (i.e. fewer-stubs) implementation of System.Data.Linq.
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / HiddenField.cs
1 //
2 // System.Web.UI.WebControls.HiddenField.cs
3 //
4 // Authors:
5 //  Lluis Sanchez Gual (lluis@novell.com)
6 //
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32 using System.Web.UI;
33 using System.ComponentModel;
34
35 namespace System.Web.UI.WebControls
36 {
37         public class HiddenField : Control, IPostBackDataHandler
38         {
39
40                 static readonly object ValueChangedEvent = new object ();
41
42                 public event EventHandler ValueChanged
43                 {
44                         add { Events.AddHandler (ValueChangedEvent, value); }
45                         remove { Events.RemoveHandler (ValueChangedEvent, value); }
46                 }
47
48                 [Bindable (true)]
49                 public virtual string Value {
50                         get {
51                                 return ViewState.GetString ("Value", "");
52                         }
53                         set {
54                                 ViewState ["Value"] = value;
55                         }
56                 }
57
58                 public override bool EnableTheming {
59                         get {
60                                 return false;
61                         }
62                         set {
63                                 throw new NotSupportedException ();
64                         }
65                 }
66
67                 public override string SkinID {
68                         get {
69                                 return String.Empty;
70                         }
71                         set {
72                                 throw new NotSupportedException ();
73                         }
74                 }
75
76                 public override void Focus ()
77                 {
78                         throw new NotSupportedException ();
79                 }
80
81                 protected virtual void OnValueChanged (EventArgs e)
82                 {
83                         EventHandler h = (EventHandler) Events [ValueChangedEvent];
84                         if (h != null)
85                                 h (this, e);
86                 }
87
88                 protected virtual bool LoadPostData (string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
89                 {
90                         if (Value != postCollection [postDataKey]) {
91                                 Value = postCollection [postDataKey];
92                                 return true;
93                         }
94                         return false;
95                 }
96
97                 protected virtual void RaisePostDataChangedEvent ()
98                 {
99                         ValidateEvent (UniqueID, String.Empty);
100                         OnValueChanged (EventArgs.Empty);
101                 }
102
103                 protected override ControlCollection CreateControlCollection ()
104                 {
105                         return new System.Web.UI.EmptyControlCollection (this);
106                 }
107
108                 protected internal override void OnPreRender (EventArgs e)
109                 {
110                         base.OnPreRender (e);
111                 }
112
113                 protected internal override void Render (HtmlTextWriter writer)
114                 {
115                         Page page = Page;
116                         string uniqueid = UniqueID;
117                         if (page != null)
118                                 page.ClientScript.RegisterForEventValidation (uniqueid);
119                         
120                         writer.AddAttribute (HtmlTextWriterAttribute.Type, "hidden", false);
121
122                         if (!String.IsNullOrEmpty (ClientID))
123                                 writer.AddAttribute (HtmlTextWriterAttribute.Id, ClientID);
124
125                         if (!String.IsNullOrEmpty (uniqueid))
126                                 writer.AddAttribute (HtmlTextWriterAttribute.Name, uniqueid);
127
128                         if (!String.IsNullOrEmpty (Value))
129                                 writer.AddAttribute (HtmlTextWriterAttribute.Value, Value);
130
131                         writer.RenderBeginTag (HtmlTextWriterTag.Input);
132                         writer.RenderEndTag (); 
133                 }
134
135                 #region IPostBackDataHandler Members
136
137                 bool IPostBackDataHandler.LoadPostData (string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
138                 {
139                         return LoadPostData (postDataKey, postCollection);
140                 }
141
142                 void IPostBackDataHandler.RaisePostDataChangedEvent ()
143                 {
144                         RaisePostDataChangedEvent ();
145                 }
146
147                 #endregion
148         }
149 }
150 #endif