HtmlInputText.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* System.Web.UI.HtmlControls
  2. * Authors
  3. * Leen Toelen ([email protected])
  4. */
  5. using System;
  6. using System.Collections.Specialized;
  7. using System.ComponentModel;
  8. using System.Globalization;
  9. using System.Web;
  10. using System.Web.UI;
  11. namespace System.Web.UI.HtmlControls{
  12. [DefaultEvent("ServerChange")]
  13. [ValidationProperty("Value")]
  14. public class HtmlInputText : HtmlInputControl, IPostBackDataHandler{
  15. private static readonly object EventServerChange = new object ();
  16. public HtmlInputText(string type):base(type){}
  17. public HtmlInputText():base("text"){}
  18. protected override void OnPreRender(EventArgs e){
  19. if (Events[EventServerChange] != null && !Disabled){
  20. ViewState.SetItemDirty("value",false);
  21. }
  22. }
  23. protected virtual void OnServerChange (EventArgs e)
  24. {
  25. EventHandler handler = (EventHandler) Events [EventServerChange];
  26. if (handler != null) handler (this, e);
  27. }
  28. protected override void RenderAttributes(HtmlTextWriter writer){
  29. //hide value when password box
  30. if (String.Compare (Type, "password",true) != 0)
  31. ViewState.Remove("value");
  32. base.RenderAttributes(writer);
  33. }
  34. bool IPostBackDataHandler.LoadPostData (string postDataKey,
  35. NameValueCollection postCollection)
  36. {
  37. string currentValue = Value;
  38. string[] postedValue = postCollection.GetValues (postDataKey);
  39. if (!currentValue.Equals (postedValue)){
  40. Value = postedValue [0];
  41. return true;
  42. }
  43. return false;
  44. }
  45. void IPostBackDataHandler.RaisePostDataChangedEvent ()
  46. {
  47. OnServerChange (EventArgs.Empty);
  48. }
  49. [WebCategory("Action")]
  50. [WebSysDescription("Fires when the the text within the control changes.")]
  51. public event EventHandler ServerChange{
  52. add{
  53. Events.AddHandler(EventServerChange, value);
  54. }
  55. remove{
  56. Events.RemoveHandler(EventServerChange, value);
  57. }
  58. }
  59. [DefaultValue("")]
  60. [WebCategory("Behavior")]
  61. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  62. public int MaxLength{
  63. get{
  64. string attr = (String) ViewState["maxlength"];
  65. if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
  66. return -1;
  67. }
  68. set{
  69. Attributes["maxlength"] = AttributeToString(value);
  70. }
  71. }
  72. [DefaultValue("")]
  73. [WebCategory("Appearance")]
  74. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  75. public int Size{
  76. get{
  77. string attr = (String) ViewState["size"];
  78. if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
  79. return -1;
  80. }
  81. set{
  82. Attributes["size"] = AttributeToString(value);
  83. }
  84. }
  85. public override string Value{
  86. get{
  87. string attr = Attributes["value"];
  88. if (attr != null) return attr;
  89. return String.Empty;
  90. }
  91. set{
  92. Attributes["value"] = AttributeToString(value);
  93. }
  94. }
  95. } // class HtmlInputText
  96. } // namespace System.Web.UI.HtmlControls