Label.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: Label
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 100%
  10. *
  11. * (C) Gaurav Vaish (2001)
  12. */
  13. using System;
  14. using System.ComponentModel;
  15. using System.Web;
  16. using System.Web.UI;
  17. namespace System.Web.UI.WebControls
  18. {
  19. [DefaultProperty("Text")]
  20. //[Designer("??")]
  21. [ControlBuilder(typeof(LabelControlBuilder))]
  22. //[DataBindingHandler("??")]
  23. [ParseChildren(false)]
  24. [ToolboxData("<{0}:Label runat=\"server\">Label</{0}:Label>")]
  25. public class Label : WebControl
  26. {
  27. public Label(): base()
  28. {
  29. }
  30. internal Label(HtmlTextWriterTag tagKey): base(tagKey)
  31. {
  32. }
  33. public virtual string Text
  34. {
  35. get
  36. {
  37. object o = ViewState["Text"];
  38. if(o!=null)
  39. return (string)o;
  40. return String.Empty;
  41. }
  42. set
  43. {
  44. ViewState["Text"] = value;
  45. }
  46. }
  47. protected override void AddParsedSubObject(object obj)
  48. {
  49. if(HasControls())
  50. {
  51. AddParsedSubObject(obj);
  52. return;
  53. }
  54. if(obj is LiteralControl)
  55. {
  56. Text = ((LiteralControl)obj).Text;
  57. return;
  58. }
  59. if(Text.Length > 0)
  60. {
  61. AddParsedSubObject(Text);
  62. Text = String.Empty;
  63. }
  64. AddParsedSubObject(obj);
  65. }
  66. protected override void LoadViewState(object savedState)
  67. {
  68. if(savedState != null)
  69. {
  70. base.LoadViewState(savedState);
  71. string savedText = (string)ViewState["Text"];
  72. if(savedText != null)
  73. Text = savedText;
  74. }
  75. }
  76. protected override void RenderContents(HtmlTextWriter writer)
  77. {
  78. if(HasControls())
  79. {
  80. RenderContents(writer);
  81. } else
  82. {
  83. writer.Write(Text);
  84. }
  85. }
  86. }
  87. }