HtmlInputText.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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",true) != 0)
  27. ViewState.Remove("value");
  28. base.RenderAttributes(writer);
  29. }
  30. public bool LoadPostData(string postDataKey, NameValueCollection postCollection){
  31. string currentValue = Value;
  32. string[] postedValue = postCollection.GetValues(postDataKey);
  33. if (!currentValue.Equals(postedValue)){
  34. Value = postedValue[0];
  35. return true;
  36. }
  37. return false;
  38. }
  39. public void RaisePostDataChangedEvent(){
  40. OnServerChange(EventArgs.Empty);
  41. }
  42. public event EventHandler ServerChange{
  43. add{
  44. Events.AddHandler(EventServerChange, value);
  45. }
  46. remove{
  47. Events.RemoveHandler(EventServerChange, value);
  48. }
  49. }
  50. public int MaxLength{
  51. get{
  52. string attr = (String) ViewState["maxlength"];
  53. if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
  54. return -1;
  55. }
  56. set{
  57. Attributes["maxlength"] = AttributeToString(value);
  58. }
  59. }
  60. public int Size{
  61. get{
  62. string attr = (String) ViewState["size"];
  63. if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
  64. return -1;
  65. }
  66. set{
  67. Attributes["size"] = AttributeToString(value);
  68. }
  69. }
  70. public override string Value{
  71. get{
  72. string attr = Attributes["value"];
  73. if (attr != null) return attr;
  74. return String.Empty;
  75. }
  76. set{
  77. Attributes["value"] = AttributeToString(value);
  78. }
  79. }
  80. } // class HtmlInputText
  81. } // namespace System.Web.UI.HtmlControls