2
0

HtmlContainerControl.cs 2.7 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. protected string _tagName;
  35. public HtmlContainerControl() : base(){}
  36. public HtmlContainerControl(string tag) : base(tag) {}
  37. public virtual string InnerHtml
  38. {
  39. get
  40. {
  41. return _innerHtml;
  42. }
  43. set
  44. {
  45. _innerHtml = value;
  46. _doText = false;
  47. _doChildren = false;
  48. }
  49. }
  50. public virtual string InnerText
  51. {
  52. get
  53. {
  54. return _innerText;
  55. }
  56. set
  57. {
  58. _innerText = value;
  59. _doText = true;
  60. _doChildren = false;
  61. }
  62. }
  63. protected override void Render(HtmlTextWriter writer)
  64. {
  65. if(_doChildren) RenderChildren(writer);
  66. else if(_doText) Page.Server.HtmlEncode(_innerText, writer);
  67. else writer.Write(_innerHtml);
  68. }
  69. protected virtual void RenderEndTag(HtmlTextWriter writer){}
  70. }
  71. }