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;
33 namespace System.Web.UI.WebControls {
34 [DataBindingHandler ("System.Web.UI.Design.TextDataBindingHandler, " + Consts.AssemblySystem_Design)]
35 [DefaultEvent ("TextChanged")]
36 [DefaultProperty ("Text")]
37 [ValidationProperty ("Text")]
38 [ControlBuilder (typeof (TextBoxControlBuilder))]
40 [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
41 [ParseChildren (true, "Text")]
42 [ControlValueProperty ("Text", null)]
44 [ParseChildren (false)]
46 public class TextBox : WebControl, IPostBackDataHandler
48 , IEditableTextControl, ITextControl
51 protected override void AddAttributesToRender (HtmlTextWriter w)
54 Page.VerifyRenderingInServerForm (this);
56 base.AddAttributesToRender (w);
59 case TextBoxMode.MultiLine:
61 w.AddAttribute (HtmlTextWriterAttribute.Cols, Columns.ToString ());
63 w.AddAttribute (HtmlTextWriterAttribute.Rows, Rows.ToString ());
65 w.AddAttribute (HtmlTextWriterAttribute.Wrap, "off");
69 case TextBoxMode.SingleLine:
70 case TextBoxMode.Password:
72 if (TextMode == TextBoxMode.Password)
73 w.AddAttribute (HtmlTextWriterAttribute.Type, "password");
75 w.AddAttribute (HtmlTextWriterAttribute.Type, "text");
76 w.AddAttribute (HtmlTextWriterAttribute.Value, Text);
80 w.AddAttribute (HtmlTextWriterAttribute.Size, Columns.ToString ());
83 w.AddAttribute (HtmlTextWriterAttribute.Maxlength, MaxLength.ToString ());
88 w.AddAttribute (HtmlTextWriterAttribute.Onchange, Page.ClientScript.GetPostBackClientHyperlink (this, ""));
91 w.AddAttribute (HtmlTextWriterAttribute.ReadOnly, "ReadOnly");
93 w.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
96 protected override void AddParsedSubObject (object obj)
98 LiteralControl l = obj as LiteralControl;
109 override void OnPreRender (EventArgs e)
111 // What do i do here?
112 base.OnPreRender (e);
115 [MonoTODO ("Am I missing something here")]
121 override void Render (HtmlTextWriter w)
123 // Why didn't msft just override RenderContents!?
125 if (TextMode == TextBoxMode.MultiLine)
126 HttpUtility.HtmlEncode (Text, w);
132 protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
134 throw new NotImplementedException ();
138 protected virtual void RaisePostDataChangedEvent ()
140 throw new NotImplementedException ();
144 bool IPostBackDataHandler.LoadPostData (string key, NameValueCollection col)
146 if (Text != col [key]) {
154 void IPostBackDataHandler.RaisePostDataChangedEvent ()
156 OnTextChanged (EventArgs.Empty);
161 protected override object SaveViewState ()
163 return base.SaveViewState ();
168 [DefaultValue (AutoCompleteType.None)]
171 public virtual AutoCompleteType AutoCompleteType
174 throw new NotImplementedException ();
177 throw new NotImplementedException ();
182 [DefaultValue(false)]
186 [WebSysDescription ("")]
187 [WebCategory ("Behavior")]
188 public virtual bool AutoPostBack {
190 return ViewState.GetBool ("AutoPostBack", false);
193 ViewState ["AutoPostBack"] = value;
198 [DefaultValue (false)]
200 public virtual bool CausesValidation
203 return ViewState.GetBool ("CausesValidation", false);
206 ViewState["CausesValidation"] = value;
215 [WebSysDescription ("")]
216 [WebCategory ("Appearance")]
217 public virtual int Columns {
219 return ViewState.GetInt ("Columns", 0);
222 ViewState ["Columns"] = value;
233 [WebSysDescription ("")]
234 [WebCategory ("Behavior")]
235 public virtual int MaxLength {
237 return ViewState.GetInt ("MaxLength", 0);
240 ViewState ["MaxLength"] = value;
245 [DefaultValue(false)]
249 [WebSysDescription ("")]
250 [WebCategory ("Behavior")]
251 public virtual bool ReadOnly {
253 return ViewState.GetBool ("ReadOnly", false);
256 ViewState ["ReadOnly"] = value;
267 [WebSysDescription ("")]
268 [WebCategory ("Behavior")]
269 public virtual int Rows {
271 return ViewState.GetInt ("Rows", 0);
274 ViewState ["Rows"] = value;
278 #if NET_2_0 && HAVE_CONTROL_ADAPTERS
279 protected virtual new
283 HtmlTextWriterTag TagKey {
285 return TextMode == TextBoxMode.MultiLine ? HtmlTextWriterTag.Textarea : HtmlTextWriterTag.Input;
290 [Bindable(true, BindingDirection.TwoWay)]
295 [PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty)]
298 [Editor ("System.ComponentModel.Design.MultilineStringEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
300 [WebSysDescription ("")]
301 [WebCategory ("Appearance")]
302 public virtual string Text {
304 return ViewState.GetString ("Text", "");
307 ViewState ["Text"] = value;
308 if (TextMode == TextBoxMode.Password)
309 ViewState.SetItemDirty ("Text", false);
313 [DefaultValue(TextBoxMode.SingleLine)]
317 [WebSysDescription ("")]
318 [WebCategory ("Behavior")]
319 public virtual TextBoxMode TextMode {
321 return (TextBoxMode) ViewState.GetInt ("TextMode", (int) TextBoxMode.SingleLine);
324 ViewState ["TextMode"] = (int) value;
331 public string ValidationGroup
334 return ViewState.GetString ("ValidationGroup", "");
337 ViewState ["ValidationGroup"] = value;
343 [WebSysDescription ("")]
344 [WebCategory ("Layout")]
345 public virtual bool Wrap {
347 return ViewState.GetBool ("Wrap", true);
350 ViewState ["Wrap"] = value;
354 protected virtual void OnTextChanged (EventArgs e)
356 EventHandler h = (EventHandler) Events [TextChangedEvent];
361 static readonly object TextChangedEvent = new object ();
363 [WebSysDescription ("")]
364 [WebCategory ("Action")]
365 public event EventHandler TextChanged {
366 add { Events.AddHandler (TextChangedEvent, value); }
367 remove { Events.RemoveHandler (TextChangedEvent, value); }