2
0

Label.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. //Currently mono does not handle Type in attributes
  22. //[ControlBuilder(typeof(LabelControlBuilder))]
  23. //[DataBindingHandler("??")]
  24. [ParseChildren(false)]
  25. [PersistChildren(false)]
  26. [ToolboxData("<{0}:Label runat=\"server\">Label</{0}:Label>")]
  27. public class Label : WebControl
  28. {
  29. public Label (): base ()
  30. {
  31. }
  32. internal Label (HtmlTextWriterTag tagKey) : base (tagKey)
  33. {
  34. }
  35. public virtual string Text
  36. {
  37. get {
  38. object o = ViewState ["Text"];
  39. return (o == null) ? String.Empty : (string) o;
  40. }
  41. set { ViewState ["Text"] = value; }
  42. }
  43. protected override void AddParsedSubObject (object obj)
  44. {
  45. if(HasControls ()){
  46. base.AddParsedSubObject (obj);
  47. return;
  48. }
  49. if(obj is LiteralControl){
  50. Text = ((LiteralControl) obj).Text;
  51. return;
  52. }
  53. if(Text.Length > 0){
  54. base.AddParsedSubObject (new LiteralControl (Text));
  55. Text = String.Empty;
  56. }
  57. base.AddParsedSubObject (obj);
  58. }
  59. protected override void LoadViewState (object savedState)
  60. {
  61. if(savedState != null) {
  62. base.LoadViewState (savedState);
  63. string savedText = ViewState ["Text"] as string;
  64. if(savedText != null)
  65. Text = savedText;
  66. }
  67. }
  68. protected override void RenderContents (HtmlTextWriter writer)
  69. {
  70. if(HasControls ())
  71. base.RenderContents (writer);
  72. else
  73. writer.Write (Text);
  74. }
  75. }
  76. }