Literal.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. namespace System.Web.UI.WebControls
  17. {
  18. public class Literal : Control
  19. {
  20. public Literal(): base()
  21. {
  22. }
  23. public 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 ControlCollection CreateControlCollection()
  38. {
  39. return new EmptyControlCollection(this);
  40. }
  41. protected override void AddParsedSubObject(object obj)
  42. {
  43. if(obj is LiteralControl)
  44. {
  45. Text = ((LiteralControl)obj).Text;
  46. return;
  47. }
  48. throw new HttpException(HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "Literal", obj.GetType().Name.ToString()));
  49. }
  50. protected override void Render(HtmlTextWriter writer)
  51. {
  52. if(Text.Length > 0)
  53. {
  54. writer.Write(Text);
  55. }
  56. }
  57. }
  58. }