1 /* System.Web.UI.HtmlControls
3 * Leen Toelen (toelen@hotmail.com)
7 using System
.Collections
.Specialized
;
8 using System
.ComponentModel
;
9 using System
.Globalization
;
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];
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
{
65 Events
.AddHandler(EventServerChange
, value);
68 Events
.RemoveHandler(EventServerChange
, value);
73 [WebCategory("Behavior")]
74 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
77 string attr
= (String
) ViewState
["maxlength"];
78 if (attr
!= null) return Int32
.Parse(attr
, CultureInfo
.InvariantCulture
);
82 Attributes
["maxlength"] = AttributeToString(value);
87 [WebCategory("Appearance")]
88 [DesignerSerializationVisibility(DesignerSerializationVisibility
.Hidden
)]
91 string attr
= (String
) ViewState
["size"];
92 if (attr
!= null) return Int32
.Parse(attr
, CultureInfo
.InvariantCulture
);
96 Attributes
["size"] = AttributeToString(value);
100 public override string Value
{
102 string attr
= Attributes
["value"];
103 if (attr
!= null) return attr
;
107 Attributes
["value"] = AttributeToString(value);
111 } // class HtmlInputText
112 } // namespace System.Web.UI.HtmlControls