**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlInputText.cs
blobcbbbb33e5b9f288d2f2e875b4315dc28e541cfc2
1 /* System.Web.UI.HtmlControls
2 * Authors
3 * Leen Toelen (toelen@hotmail.com)
4 */
6 using System;
7 using System.Collections.Specialized;
8 using System.ComponentModel;
9 using System.Globalization;
10 using System.Web;
11 using System.Web.UI;
13 namespace System.Web.UI.HtmlControls{
15 [DefaultEvent("ServerChange")]
16 [ValidationProperty("Value")]
17 public class HtmlInputText : HtmlInputControl, IPostBackDataHandler{
19 private static readonly object EventServerChange = new object ();
21 public HtmlInputText(string type):base(type){}
22 public HtmlInputText():base("text"){}
24 protected override void OnPreRender (EventArgs e)
26 if (Events [EventServerChange] == null && !Disabled)
27 ViewState.SetItemDirty("value",false);
30 protected virtual void OnServerChange (EventArgs e)
32 EventHandler handler = (EventHandler) Events [EventServerChange];
33 if (handler != null) handler (this, e);
36 protected override void RenderAttributes(HtmlTextWriter writer){
37 //hide value when password box
38 if (String.Compare (Type, "password",true) == 0)
39 ViewState.Remove ("value");
41 base.RenderAttributes(writer);
44 bool IPostBackDataHandler.LoadPostData (string postDataKey,
45 NameValueCollection postCollection)
47 string currentValue = Value;
48 string[] postedValue = postCollection.GetValues (postDataKey);
49 if (!currentValue.Equals (postedValue)){
50 Value = postedValue [0];
51 return true;
53 return false;
56 void IPostBackDataHandler.RaisePostDataChangedEvent ()
58 OnServerChange (EventArgs.Empty);
61 [WebCategory("Action")]
62 [WebSysDescription("Fires when the the text within the control changes.")]
63 public event EventHandler ServerChange{
64 add{
65 Events.AddHandler(EventServerChange, value);
67 remove{
68 Events.RemoveHandler(EventServerChange, value);
72 [DefaultValue("")]
73 [WebCategory("Behavior")]
74 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
75 public int MaxLength{
76 get{
77 string attr = (String) ViewState["maxlength"];
78 if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
79 return -1;
81 set{
82 Attributes["maxlength"] = AttributeToString(value);
86 [DefaultValue("")]
87 [WebCategory("Appearance")]
88 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
89 public int Size{
90 get{
91 string attr = (String) ViewState["size"];
92 if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
93 return -1;
95 set{
96 Attributes["size"] = AttributeToString(value);
100 public override string Value{
101 get{
102 string attr = Attributes["value"];
103 if (attr != null) return attr;
104 return String.Empty;
106 set{
107 Attributes["value"] = AttributeToString(value);
111 } // class HtmlInputText
112 } // namespace System.Web.UI.HtmlControls