HtmlContainerControl.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // System.Web.UI.HtmlControls.HtmlContainerControl.cs
  3. //
  4. // Author
  5. // Bob Smith <[email protected]>
  6. //
  7. // (C) Bob Smith
  8. //
  9. using System;
  10. using System.Web;
  11. using System.Web.UI;
  12. //LAMESPEC: The dox talk about HttpException but are very ambigious.
  13. //TODO: Check to see if Render really is overridden instead of a LiteralControl being added. It apears that this is the
  14. //case due to testing. Anything inside the block is overwritten by the content of this control, so it doesnt apear
  15. //to do anything with children.
  16. // a doc references this. add? protected override ControlCollection CreateControlCollection();
  17. //TODO: If Test.InnerText = Test.InnerHtml without ever assigning anything into InnerHtml, you get this:
  18. // Exception Details: System.Web.HttpException: Cannot get inner content of Message because the contents are not literal.
  19. //[HttpException (0x80004005): Cannot get inner content of Message because the contents are not literal.]
  20. // System.Web.UI.HtmlControls.HtmlContainerControl.get_InnerHtml() +278
  21. // ASP.test3_aspx.AnchorBtn_Click(Object Source, EventArgs E) in \\genfs2\www24\bobsmith11\test3.aspx:6
  22. // System.Web.UI.HtmlControls.HtmlAnchor.OnServerClick(EventArgs e) +108
  23. // System.Web.UI.HtmlControls.HtmlAnchor.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +26
  24. // System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
  25. // System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +149
  26. // System.Web.UI.Page.ProcessRequestMain() +660
  27. namespace System.Web.UI.HtmlControls
  28. {
  29. public abstract class HtmlContainerControl : HtmlControl{
  30. private string _innerHtml = String.Empty;
  31. private string _innerText = String.Empty;
  32. private bool _doText = false;
  33. private bool _doChildren = true;
  34. public HtmlContainerControl() : base(){}
  35. public HtmlContainerControl(string tag) : base(tag) {}
  36. public virtual string InnerHtml
  37. {
  38. get { return _innerHtml; }
  39. set {
  40. _innerHtml = value;
  41. _doText = false;
  42. _doChildren = false;
  43. }
  44. }
  45. public virtual string InnerText
  46. {
  47. get { return _innerText; }
  48. set {
  49. _innerText = value;
  50. _doText = true;
  51. _doChildren = false;
  52. }
  53. }
  54. protected override void Render(HtmlTextWriter writer)
  55. {
  56. base.Render (writer);
  57. if (_doChildren)
  58. RenderChildren(writer);
  59. else if (_doText)
  60. writer.Write (HttpUtility.HtmlEncode (_innerText));
  61. else
  62. writer.Write (_innerHtml);
  63. RenderEndTag (writer);
  64. }
  65. protected virtual void RenderEndTag (HtmlTextWriter writer)
  66. {
  67. writer.WriteEndTag (TagName);
  68. }
  69. }
  70. }