* Makefile: Add reference to ICSharpCode.SharpZipLib.dll.
[mono.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlInputText.cs
1 //
2 // System.Web.UI.HtmlControls.HtmlInputText.cs
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
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:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
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.
27 //
28
29 using System.ComponentModel;
30 using System.Collections.Specialized;
31 using System.Globalization;
32 using System.Security.Permissions;
33
34 namespace System.Web.UI.HtmlControls {
35
36         // CAS
37         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38         [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39         // attributes
40         [DefaultEvent ("ServerChange")]
41         [ValidationProperty ("Value")]
42 #if NET_2_0
43         [SupportsEventValidation]
44 #endif
45         public class HtmlInputText : HtmlInputControl, IPostBackDataHandler 
46         {
47                 static readonly object serverChangeEvent = new object ();
48
49                 public HtmlInputText ()
50                         : base ("text")
51                 {
52                 }
53
54                 public HtmlInputText (string type)
55                         : base (type)
56                 {
57                 }
58
59                 [DefaultValue ("")]
60                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
61                 [WebSysDescription("")]
62                 [WebCategory("Behavior")]
63                 public int MaxLength {
64                         get {
65                                 string s = Attributes ["maxlength"];
66                                 return (s == null) ? -1 : Convert.ToInt32 (s);
67                         }
68                         set {
69                                 if (value == -1)
70                                         Attributes.Remove ("maxlength");
71                                 else
72                                         Attributes ["maxlength"] = value.ToString ();
73                         }
74                 }
75
76 #if NET_2_0
77                 [DefaultValue (-1)]
78 #else
79                 [DefaultValue ("")]
80 #endif
81                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
82                 [WebSysDescription("")]
83                 [WebCategory("Appearance")]
84                 public int Size {
85                         get {
86                                 string s = Attributes ["size"];
87                                 return (s == null) ? -1 : Convert.ToInt32 (s);
88                         }
89                         set {
90                                 if (value == -1)
91                                         Attributes.Remove ("size");
92                                 else
93                                         Attributes ["size"] = value.ToString ();
94                         }
95                 }
96
97                 public override string Value {
98                         get {
99                                 string s = Attributes ["value"];
100                                 return (s == null) ? String.Empty : s;
101                         }
102                         set {
103                                 if (value == null)
104                                         Attributes.Remove ("value");
105                                 else
106                                         Attributes ["value"] = value;
107                         }
108                 }
109
110
111 #if NET_2_0
112                 protected internal override void Render (HtmlTextWriter writer)
113                 {
114                         Page page = Page;
115                         if (page != null)
116                                 page.ClientScript.RegisterForEventValidation (UniqueID);
117                         base.Render (writer);
118                 }
119 #endif
120
121 #if NET_2_0
122                 protected internal
123 #else           
124                 protected
125 #endif          
126                 override void OnPreRender (EventArgs e)
127                 {
128                         base.OnPreRender (e);
129                         if (Page != null && !Disabled) {
130                                 Page.RegisterRequiresPostBack (this);
131 #if NET_2_0
132                                 Page.RegisterEnabledControl (this);
133 #endif
134                         }
135                 }
136
137                 protected virtual void OnServerChange (EventArgs e)
138                 {
139                         EventHandler serverChange = (EventHandler) Events [serverChangeEvent];
140                         if (serverChange != null)
141                                 serverChange (this, e);
142                 }
143
144                 protected override void RenderAttributes (HtmlTextWriter writer)
145                 {
146                         // the Type property can be, indirectly, changed by using the Attributes property
147                         if (String.Compare (Type, 0, "password", 0, 8, true, CultureInfo.InvariantCulture) == 0) {
148                                 Attributes.Remove ("value");
149                         }
150
151                         base.RenderAttributes (writer);
152                 }
153
154                 bool LoadPostDataInternal (string postDataKey, NameValueCollection postCollection)
155                 {
156                         string s = postCollection [postDataKey];
157                         if (Value != s) {
158                                 Value = s;
159                                 return true;
160                         }
161                         return false;
162                 }
163
164                 void RaisePostDataChangedEventInternal ()
165                 {
166                         OnServerChange (EventArgs.Empty);
167                 }
168
169 #if NET_2_0
170                 protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
171                 {
172                         return LoadPostDataInternal (postDataKey, postCollection);
173                 }
174
175                 protected virtual void RaisePostDataChangedEvent ()
176                 {
177                         ValidateEvent (UniqueID, String.Empty);
178                         RaisePostDataChangedEventInternal ();
179                 }
180 #endif
181
182                 bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
183                 {
184 #if NET_2_0
185                         return LoadPostData (postDataKey, postCollection);
186 #else
187                         return LoadPostDataInternal (postDataKey, postCollection);
188 #endif
189                 }
190
191                 void IPostBackDataHandler.RaisePostDataChangedEvent ()
192                 {
193 #if NET_2_0
194                         RaisePostDataChangedEvent ();
195 #else
196                         RaisePostDataChangedEventInternal ();
197 #endif
198                 }
199
200
201                 [WebSysDescription("")]
202                 [WebCategory("Action")]
203                 public event EventHandler ServerChange {
204                         add { Events.AddHandler (serverChangeEvent, value); }
205                         remove { Events.RemoveHandler (serverChangeEvent, value); }
206                 }
207         }
208 }