2 // System.Web.UI.HtmlControls.HtmlInputText.cs
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.ComponentModel;
30 using System.Collections.Specialized;
31 using System.Globalization;
32 using System.Security.Permissions;
34 namespace System.Web.UI.HtmlControls {
37 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40 [DefaultEvent ("ServerChange")]
41 [ValidationProperty ("Value")]
43 [SupportsEventValidation]
45 public class HtmlInputText : HtmlInputControl, IPostBackDataHandler {
47 private static readonly object serverChangeEvent = new object ();
50 public HtmlInputText ()
55 public HtmlInputText (string type)
62 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
63 [WebSysDescription("")]
64 [WebCategory("Behavior")]
65 public int MaxLength {
67 string s = Attributes ["maxlength"];
68 return (s == null) ? -1 : Convert.ToInt32 (s);
72 Attributes.Remove ("maxlength");
74 Attributes ["maxlength"] = value.ToString ();
83 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
84 [WebSysDescription("")]
85 [WebCategory("Appearance")]
88 string s = Attributes ["size"];
89 return (s == null) ? -1 : Convert.ToInt32 (s);
93 Attributes.Remove ("size");
95 Attributes ["size"] = value.ToString ();
99 public override string Value {
101 string s = Attributes ["value"];
102 return (s == null) ? String.Empty : s;
106 Attributes.Remove ("value");
108 Attributes ["value"] = value;
118 override void OnPreRender (EventArgs e)
120 base.OnPreRender (e);
122 Page.RegisterRequiresPostBack (this);
126 protected virtual void OnServerChange (EventArgs e)
128 EventHandler serverChange = (EventHandler) Events [serverChangeEvent];
129 if (serverChange != null)
130 serverChange (this, e);
133 protected override void RenderAttributes (HtmlTextWriter writer)
135 // the Type property can be, indirectly, changed by using the Attributes property
136 if (String.Compare (Type, 0, "password", 0, 8, true, CultureInfo.InvariantCulture) == 0) {
137 Attributes.Remove ("value");
140 base.RenderAttributes (writer);
143 bool LoadPostDataInternal (string postDataKey, NameValueCollection postCollection)
145 string s = postCollection [postDataKey];
153 void RaisePostDataChangedEventInternal ()
155 OnServerChange (EventArgs.Empty);
159 protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
161 return LoadPostDataInternal (postDataKey, postCollection);
164 protected virtual void RaisePostDataChangedEvent ()
166 RaisePostDataChangedEventInternal ();
170 bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
173 return LoadPostData (postDataKey, postCollection);
175 return LoadPostDataInternal (postDataKey, postCollection);
179 void IPostBackDataHandler.RaisePostDataChangedEvent ()
182 RaisePostDataChangedEvent ();
184 RaisePostDataChangedEventInternal ();
189 [WebSysDescription("")]
190 [WebCategory("Action")]
191 public event EventHandler ServerChange {
192 add { Events.AddHandler (serverChangeEvent, value); }
193 remove { Events.RemoveHandler (serverChangeEvent, value); }