2 // System.Web.UI.WebControls.HiddenField.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
33 using System.ComponentModel;
35 namespace System.Web.UI.WebControls
37 public class HiddenField : Control, IPostBackDataHandler
40 static readonly object ValueChangedEvent = new object ();
42 public event EventHandler ValueChanged
44 add { Events.AddHandler (ValueChangedEvent, value); }
45 remove { Events.RemoveHandler (ValueChangedEvent, value); }
49 public virtual string Value {
51 return ViewState.GetString ("Value", "");
54 ViewState ["Value"] = value;
58 public override bool EnableTheming {
63 throw new NotSupportedException ();
67 public override string SkinID {
72 throw new NotSupportedException ();
76 public override void Focus ()
78 throw new NotSupportedException ();
81 protected virtual void OnValueChanged (EventArgs e)
83 EventHandler h = (EventHandler) Events [ValueChangedEvent];
88 protected virtual bool LoadPostData (string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
90 if (Value != postCollection [postDataKey]) {
91 Value = postCollection [postDataKey];
97 protected virtual void RaisePostDataChangedEvent ()
99 OnValueChanged (EventArgs.Empty);
102 protected override ControlCollection CreateControlCollection ()
104 return new System.Web.UI.EmptyControlCollection (this);
107 protected internal override void OnPreRender (EventArgs e)
109 base.OnPreRender (e);
112 protected internal override void Render (HtmlTextWriter writer)
114 writer.AddAttribute (HtmlTextWriterAttribute.Type, "hidden", false);
116 if (!String.IsNullOrEmpty (ClientID))
117 writer.AddAttribute (HtmlTextWriterAttribute.Id, ClientID);
119 if (!String.IsNullOrEmpty (UniqueID))
120 writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
122 if (!String.IsNullOrEmpty (Value))
123 writer.AddAttribute (HtmlTextWriterAttribute.Value, Value);
125 writer.RenderBeginTag (HtmlTextWriterTag.Input);
126 writer.RenderEndTag ();
129 #region IPostBackDataHandler Members
131 bool IPostBackDataHandler.LoadPostData (string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
133 return LoadPostData (postDataKey, postCollection);
136 void IPostBackDataHandler.RaisePostDataChangedEvent ()
138 RaisePostDataChangedEvent ();