2
0

Label.cs 1.8 KB

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