**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web / System.Web.UI.HtmlControls / HtmlContainerControl.cs
bloba24d8ca6d71342918357cb110d8a7c6c921a655b
1 //
2 // System.Web.UI.HtmlControls.HtmlContainerControl.cs
3 //
4 // Authors:
5 // Bob Smith <bob@thestuff.net>
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 //
8 // (C) Bob Smith
9 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
12 using System;
13 using System.ComponentModel;
14 using System.Text;
15 using System.Web;
16 using System.Web.UI;
18 //LAMESPEC: The dox talk about HttpException but are very ambigious.
19 //TODO: Check to see if Render really is overridden instead of a LiteralControl being added. It apears that this is the
20 //case due to testing. Anything inside the block is overwritten by the content of this control, so it doesnt apear
21 //to do anything with children.
22 // a doc references this. add? protected override ControlCollection CreateControlCollection();
24 //TODO: If Test.InnerText = Test.InnerHtml without ever assigning anything into InnerHtml, you get this:
25 // Exception Details: System.Web.HttpException: Cannot get inner content of Message because the contents are not literal.
26 //[HttpException (0x80004005): Cannot get inner content of Message because the contents are not literal.]
27 // System.Web.UI.HtmlControls.HtmlContainerControl.get_InnerHtml() +278
28 // ASP.test3_aspx.AnchorBtn_Click(Object Source, EventArgs E) in \\genfs2\www24\bobsmith11\test3.aspx:6
29 // System.Web.UI.HtmlControls.HtmlAnchor.OnServerClick(EventArgs e) +108
30 // System.Web.UI.HtmlControls.HtmlAnchor.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +26
31 // System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
32 // System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +149
33 // System.Web.UI.Page.ProcessRequestMain() +660
36 namespace System.Web.UI.HtmlControls
38 public abstract class HtmlContainerControl : HtmlControl{
40 public HtmlContainerControl () : this ("span") {}
42 public HtmlContainerControl (string tag) : base(tag) {}
44 [HtmlControlPersistable (false)]
45 [BrowsableAttribute(false)]
46 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
47 public virtual string InnerHtml
49 get {
50 if (Controls.Count == 0)
51 return String.Empty;
53 bool is_literal = true;
54 StringBuilder text = new StringBuilder ();
55 foreach (Control ctrl in Controls) {
56 LiteralControl lc = ctrl as LiteralControl;
57 if (lc == null) {
58 is_literal = false;
59 break;
61 text.Append (lc.Text);
64 if (!is_literal)
65 throw new HttpException ("There is no literal content!");
67 return text.ToString ();
70 set {
71 Controls.Clear ();
72 Controls.Add (new LiteralControl (value));
73 ViewState ["innerhtml"] = value;
77 [HtmlControlPersistable (false)]
78 [BrowsableAttribute(false)]
79 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
80 public virtual string InnerText
82 get {
83 return HttpUtility.HtmlDecode (InnerHtml);
86 set {
87 InnerHtml = HttpUtility.HtmlEncode (value);
91 protected override void Render (HtmlTextWriter writer)
93 RenderBeginTag (writer);
94 RenderChildren (writer);
95 RenderEndTag (writer);
98 protected virtual void RenderEndTag (HtmlTextWriter writer)
100 writer.WriteEndTag (TagName);
103 protected override void RenderAttributes (HtmlTextWriter writer)
105 ViewState.Remove ("innerhtml");
106 base.RenderAttributes (writer);
109 protected override ControlCollection CreateControlCollection ()
111 return new ControlCollection (this);
114 protected override void LoadViewState (object savedState)
116 if (savedState != null) {
117 base.LoadViewState (savedState);
118 string inner = ViewState ["innerhtml"] as string;
119 if (inner != null)
120 InnerHtml = inner;