HtmlInputText.cs 2.4 KB

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