2
0

HtmlContainerControl.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // System.Web.UI.HtmlControls.HtmlContainerControl.cs
  3. //
  4. // Authors:
  5. // Bob Smith <[email protected]>
  6. // Gonzalo Paniagua Javier ([email protected])
  7. //
  8. // (C) Bob Smith
  9. // (c) 2002 Ximian, Inc. (http://www.ximian.com)
  10. //
  11. using System;
  12. using System.Text;
  13. using System.Web;
  14. using System.Web.UI;
  15. //LAMESPEC: The dox talk about HttpException but are very ambigious.
  16. //TODO: Check to see if Render really is overridden instead of a LiteralControl being added. It apears that this is the
  17. //case due to testing. Anything inside the block is overwritten by the content of this control, so it doesnt apear
  18. //to do anything with children.
  19. // a doc references this. add? protected override ControlCollection CreateControlCollection();
  20. //TODO: If Test.InnerText = Test.InnerHtml without ever assigning anything into InnerHtml, you get this:
  21. // Exception Details: System.Web.HttpException: Cannot get inner content of Message because the contents are not literal.
  22. //[HttpException (0x80004005): Cannot get inner content of Message because the contents are not literal.]
  23. // System.Web.UI.HtmlControls.HtmlContainerControl.get_InnerHtml() +278
  24. // ASP.test3_aspx.AnchorBtn_Click(Object Source, EventArgs E) in \\genfs2\www24\bobsmith11\test3.aspx:6
  25. // System.Web.UI.HtmlControls.HtmlAnchor.OnServerClick(EventArgs e) +108
  26. // System.Web.UI.HtmlControls.HtmlAnchor.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +26
  27. // System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
  28. // System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +149
  29. // System.Web.UI.Page.ProcessRequestMain() +660
  30. namespace System.Web.UI.HtmlControls
  31. {
  32. public abstract class HtmlContainerControl : HtmlControl{
  33. public HtmlContainerControl () : this ("span") {}
  34. public HtmlContainerControl (string tag) : base(tag) {}
  35. public virtual string InnerHtml
  36. {
  37. get {
  38. if (Controls.Count == 0)
  39. return String.Empty;
  40. bool is_literal = true;
  41. StringBuilder text = new StringBuilder ();
  42. foreach (Control ctrl in Controls) {
  43. LiteralControl lc = ctrl as LiteralControl;
  44. if (lc == null) {
  45. is_literal = false;
  46. break;
  47. }
  48. text.Append (lc.Text);
  49. }
  50. if (!is_literal)
  51. throw new HttpException ("There is no literal content!");
  52. return text.ToString ();
  53. }
  54. set {
  55. Controls.Clear ();
  56. Controls.Add (new LiteralControl (value));
  57. ViewState ["innerhtml"] = value;
  58. }
  59. }
  60. public virtual string InnerText
  61. {
  62. get {
  63. return InnerHtml; //FIXME: decode it
  64. }
  65. set {
  66. InnerHtml = value; //FIXME: encode it
  67. }
  68. }
  69. protected override void Render (HtmlTextWriter writer)
  70. {
  71. RenderBeginTag (writer);
  72. RenderChildren (writer);
  73. RenderEndTag (writer);
  74. }
  75. protected virtual void RenderEndTag (HtmlTextWriter writer)
  76. {
  77. writer.WriteEndTag (TagName);
  78. }
  79. protected override void RenderAttributes (HtmlTextWriter writer)
  80. {
  81. ViewState.Remove ("innerhtml");
  82. base.RenderAttributes (writer);
  83. }
  84. protected override ControlCollection CreateControlCollection ()
  85. {
  86. return new ControlCollection (this);
  87. }
  88. protected override void LoadViewState (object savedState)
  89. {
  90. if (savedState != null) {
  91. base.LoadViewState (savedState);
  92. string inner = ViewState ["innerhtml"] as string;
  93. if (inner != null)
  94. InnerHtml = inner;
  95. }
  96. }
  97. }
  98. }