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 ValidateEvent (UniqueID, String.Empty);
100 OnValueChanged (EventArgs.Empty);
103 protected override ControlCollection CreateControlCollection ()
105 return new System.Web.UI.EmptyControlCollection (this);
108 protected internal override void OnPreRender (EventArgs e)
110 base.OnPreRender (e);
113 protected internal override void Render (HtmlTextWriter writer)
116 string uniqueid = UniqueID;
118 page.ClientScript.RegisterForEventValidation (uniqueid);
120 writer.AddAttribute (HtmlTextWriterAttribute.Type, "hidden", false);
122 if (!String.IsNullOrEmpty (ClientID))
123 writer.AddAttribute (HtmlTextWriterAttribute.Id, ClientID);
125 if (!String.IsNullOrEmpty (uniqueid))
126 writer.AddAttribute (HtmlTextWriterAttribute.Name, uniqueid);
128 if (!String.IsNullOrEmpty (Value))
129 writer.AddAttribute (HtmlTextWriterAttribute.Value, Value);
131 writer.RenderBeginTag (HtmlTextWriterTag.Input);
132 writer.RenderEndTag ();
135 #region IPostBackDataHandler Members
137 bool IPostBackDataHandler.LoadPostData (string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
139 return LoadPostData (postDataKey, postCollection);
142 void IPostBackDataHandler.RaisePostDataChangedEvent ()
144 RaisePostDataChangedEvent ();