2 // System.Web.UI.WebControls.TextBox.cs
5 // Ben Maurer (bmaurer@novell.com)
7 // (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.Collections.Specialized;
30 using System.ComponentModel;
31 using System.Security.Permissions;
33 namespace System.Web.UI.WebControls {
36 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39 [DataBindingHandler ("System.Web.UI.Design.TextDataBindingHandler, " + Consts.AssemblySystem_Design)]
40 [DefaultEvent ("TextChanged")]
41 [DefaultProperty ("Text")]
42 [ValidationProperty ("Text")]
43 [ControlBuilder (typeof (TextBoxControlBuilder))]
45 [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
46 [ParseChildren (true, "Text")]
47 [ControlValueProperty ("Text", null)]
48 [SupportsEventValidation]
50 [ParseChildren (false)]
52 public class TextBox : WebControl, IPostBackDataHandler
54 , IEditableTextControl, ITextControl
57 protected override void AddAttributesToRender (HtmlTextWriter w)
60 Page.VerifyRenderingInServerForm (this);
62 base.AddAttributesToRender (w);
65 case TextBoxMode.MultiLine:
67 w.AddAttribute (HtmlTextWriterAttribute.Cols, Columns.ToString ());
69 w.AddAttribute (HtmlTextWriterAttribute.Rows, Rows.ToString ());
71 w.AddAttribute (HtmlTextWriterAttribute.Wrap, "off");
75 case TextBoxMode.SingleLine:
76 case TextBoxMode.Password:
78 if (TextMode == TextBoxMode.Password)
79 w.AddAttribute (HtmlTextWriterAttribute.Type, "password");
81 w.AddAttribute (HtmlTextWriterAttribute.Type, "text");
83 w.AddAttribute (HtmlTextWriterAttribute.Value, Text);
87 w.AddAttribute (HtmlTextWriterAttribute.Size, Columns.ToString ());
90 w.AddAttribute (HtmlTextWriterAttribute.Maxlength, MaxLength.ToString ());
95 w.AddAttribute (HtmlTextWriterAttribute.Onchange, Page.ClientScript.GetPostBackClientHyperlink (this, ""));
98 w.AddAttribute (HtmlTextWriterAttribute.ReadOnly, "ReadOnly");
101 w.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
103 w.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
107 protected override void AddParsedSubObject (object obj)
109 LiteralControl l = obj as LiteralControl;
120 override void OnPreRender (EventArgs e)
122 // What do i do here?
123 base.OnPreRender (e);
126 [MonoTODO ("Am I missing something here")]
132 override void Render (HtmlTextWriter w)
134 // Why didn't msft just override RenderContents!?
136 if (TextMode == TextBoxMode.MultiLine)
137 HttpUtility.HtmlEncode (Text, w);
144 bool LoadPostData (string postDataKey, NameValueCollection postCollection)
146 if (Text != postCollection [postDataKey]) {
147 Text = postCollection [postDataKey];
157 void RaisePostDataChangedEvent ()
159 OnTextChanged (EventArgs.Empty);
162 bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection)
164 return LoadPostData (postDataKey, postCollection);
167 void IPostBackDataHandler.RaisePostDataChangedEvent ()
169 RaisePostDataChangedEvent ();
174 protected override object SaveViewState ()
176 return base.SaveViewState ();
181 [DefaultValue (AutoCompleteType.None)]
184 public virtual AutoCompleteType AutoCompleteType
187 throw new NotImplementedException ();
190 throw new NotImplementedException ();
195 [DefaultValue(false)]
199 [WebSysDescription ("")]
200 [WebCategory ("Behavior")]
201 public virtual bool AutoPostBack {
203 return ViewState.GetBool ("AutoPostBack", false);
206 ViewState ["AutoPostBack"] = value;
211 [DefaultValue (false)]
213 public virtual bool CausesValidation
216 return ViewState.GetBool ("CausesValidation", false);
219 ViewState["CausesValidation"] = value;
228 [WebSysDescription ("")]
229 [WebCategory ("Appearance")]
230 public virtual int Columns {
232 return ViewState.GetInt ("Columns", 0);
236 throw new ArgumentOutOfRangeException("value", "Columns value has to be 0 for 'not set' or bigger than 0.");
238 ViewState ["Columns"] = value;
249 [WebSysDescription ("")]
250 [WebCategory ("Behavior")]
251 public virtual int MaxLength {
253 return ViewState.GetInt ("MaxLength", 0);
257 throw new ArgumentOutOfRangeException("value", "MaxLength value has to be 0 for 'not set' or bigger than 0.");
259 ViewState ["MaxLength"] = value;
264 [DefaultValue(false)]
268 [WebSysDescription ("")]
269 [WebCategory ("Behavior")]
270 public virtual bool ReadOnly {
272 return ViewState.GetBool ("ReadOnly", false);
275 ViewState ["ReadOnly"] = value;
286 [WebSysDescription ("")]
287 [WebCategory ("Behavior")]
288 public virtual int Rows {
290 return ViewState.GetInt ("Rows", 0);
294 throw new ArgumentOutOfRangeException("value", "Rows value has to be 0 for 'not set' or bigger than 0.");
296 ViewState ["Rows"] = value;
300 #if NET_2_0 && HAVE_CONTROL_ADAPTERS
301 protected virtual new
305 HtmlTextWriterTag TagKey {
307 return TextMode == TextBoxMode.MultiLine ? HtmlTextWriterTag.Textarea : HtmlTextWriterTag.Input;
312 [Bindable(true, BindingDirection.TwoWay)]
317 [PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty)]
320 [Editor ("System.ComponentModel.Design.MultilineStringEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
322 [WebSysDescription ("")]
323 [WebCategory ("Appearance")]
324 public virtual string Text {
326 return ViewState.GetString ("Text", "");
329 ViewState ["Text"] = value;
330 if (TextMode == TextBoxMode.Password)
331 ViewState.SetItemDirty ("Text", false);
335 [DefaultValue(TextBoxMode.SingleLine)]
339 [WebSysDescription ("")]
340 [WebCategory ("Behavior")]
341 public virtual TextBoxMode TextMode {
343 return (TextBoxMode) ViewState.GetInt ("TextMode", (int) TextBoxMode.SingleLine);
346 ViewState ["TextMode"] = (int) value;
353 public virtual string ValidationGroup
356 return ViewState.GetString ("ValidationGroup", "");
359 ViewState ["ValidationGroup"] = value;
365 [WebSysDescription ("")]
366 [WebCategory ("Layout")]
367 public virtual bool Wrap {
369 return ViewState.GetBool ("Wrap", true);
372 ViewState ["Wrap"] = value;
376 protected virtual void OnTextChanged (EventArgs e)
378 EventHandler h = (EventHandler) Events [TextChangedEvent];
383 static readonly object TextChangedEvent = new object ();
385 [WebSysDescription ("")]
386 [WebCategory ("Action")]
387 public event EventHandler TextChanged {
388 add { Events.AddHandler (TextChangedEvent, value); }
389 remove { Events.RemoveHandler (TextChangedEvent, value); }