2
0

Label.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. namespace System.Web.UI.WebControls
  14. {
  15. public class Label : WebControl
  16. {
  17. public Label(): base()
  18. {
  19. }
  20. internal Label(HtmlTextWriterTag tagKey): base(tagKey)
  21. {
  22. }
  23. public virtual string Text
  24. {
  25. get
  26. {
  27. object o = ViewState["Text"];
  28. if(o!=null)
  29. return (string)o;
  30. return String.Empty;
  31. }
  32. set
  33. {
  34. ViewState["Text"] = value;
  35. }
  36. }
  37. protected override void AddParsedSubObject(object obj)
  38. {
  39. if(HasControls())
  40. {
  41. AddParsedSubObject(obj);
  42. return;
  43. }
  44. if(obj is LiteralControl)
  45. {
  46. Text = ((LiteralControl)obj).Text;
  47. return;
  48. }
  49. if(Text.Length > 0)
  50. {
  51. AddParsedSubObject(Text);
  52. Text = String.Empty;
  53. }
  54. AddParsedSubObject(obj);
  55. }
  56. protected override void LoadViewState(object savedState)
  57. {
  58. if(savedState != null)
  59. {
  60. base.LoadViewState(savedState);
  61. string savedText = (string)ViewState["Text"];
  62. if(savedText != null)
  63. Text = savedText;
  64. }
  65. }
  66. protected override void RenderContents(HtmlTextWriter writer)
  67. {
  68. if(HasControls())
  69. {
  70. RenderContents(writer);
  71. } else
  72. {
  73. writer.Write(Text);
  74. }
  75. }
  76. }
  77. }