Label.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. object o = ViewState ["Text"];
  37. return (o == null) ? String.Empty : (string) o;
  38. }
  39. set { ViewState ["Text"] = value; }
  40. }
  41. protected override void AddParsedSubObject (object obj)
  42. {
  43. if(HasControls ()){
  44. base.AddParsedSubObject (obj);
  45. return;
  46. }
  47. if(obj is LiteralControl){
  48. Text = ((LiteralControl) obj).Text;
  49. return;
  50. }
  51. if(Text.Length > 0){
  52. base.AddParsedSubObject (new LiteralControl (Text));
  53. Text = String.Empty;
  54. }
  55. base.AddParsedSubObject (obj);
  56. }
  57. protected override void LoadViewState (object savedState)
  58. {
  59. if(savedState != null) {
  60. base.LoadViewState (savedState);
  61. string savedText = ViewState ["Text"] as string;
  62. if(savedText != null)
  63. Text = savedText;
  64. }
  65. }
  66. protected override void RenderContents (HtmlTextWriter writer)
  67. {
  68. if(HasControls ())
  69. base.RenderContents (writer);
  70. else
  71. writer.Write (Text);
  72. }
  73. }
  74. }