Literal.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: Literal
  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.Web;
  15. using System.Web.UI;
  16. using System.ComponentModel;
  17. namespace System.Web.UI.WebControls
  18. {
  19. [DefaultProperty("Text")]
  20. [ControlBuilder(typeof(LiteralControlBuilder))]
  21. //[DataBindingHandler("??")]
  22. public class Literal : Control
  23. {
  24. public Literal(): base()
  25. {
  26. }
  27. public string Text
  28. {
  29. get
  30. {
  31. object o = ViewState["Text"];
  32. if(o != null)
  33. return (string)o;
  34. return String.Empty;
  35. }
  36. set
  37. {
  38. ViewState["Text"] = value;
  39. }
  40. }
  41. protected override ControlCollection CreateControlCollection()
  42. {
  43. return new EmptyControlCollection(this);
  44. }
  45. protected override void AddParsedSubObject(object obj)
  46. {
  47. if(obj is LiteralControl)
  48. {
  49. Text = ((LiteralControl)obj).Text;
  50. return;
  51. }
  52. throw new HttpException(HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "Literal", obj.GetType().Name.ToString()));
  53. }
  54. protected override void Render(HtmlTextWriter writer)
  55. {
  56. if(Text.Length > 0)
  57. {
  58. writer.Write(Text);
  59. }
  60. }
  61. }
  62. }