move beginning of page writing into RenderBeginTag so we can properly override content in RenderContents

This commit is contained in:
Michael Becker 2024-08-11 10:13:01 -04:00
parent 94e3fcec40
commit 9e49f743f9

View File

@ -19,9 +19,9 @@ public class WebPage : Control
{ {
} }
protected override void PersistentInitializeInternal() protected override void PersistentInitializeInternal()
{ {
base.PersistentInitializeInternal(); base.PersistentInitializeInternal();
Controls.Clear(); Controls.Clear();
CreateChildControls(); CreateChildControls();
@ -33,22 +33,19 @@ public class WebPage : Control
ChildControlsCreated = true; ChildControlsCreated = true;
} }
*/ */
} }
protected virtual IEnumerable<Control> GetHeaderControls() protected virtual IEnumerable<Control> GetHeaderControls()
{ {
return [ ]; return [ ];
} }
protected override string TagName => "html"; protected override string TagName => "html";
protected override void RenderBeginTag(XmlWriter writer) protected override void RenderBeginTag(XmlWriter writer)
{ {
EnsureInitialized(); EnsureInitialized();
writer.WriteStartElement(TagName, "http://www.w3.org/1999/xhtml"); writer.WriteStartElement(TagName, "http://www.w3.org/1999/xhtml");
}
protected override void RenderContents(XmlWriter writer)
{
writer.WriteStartElement("head"); writer.WriteStartElement("head");
writer.WriteElementString("title", "Mocha Application"); writer.WriteElementString("title", "Mocha Application");
@ -89,11 +86,19 @@ public class WebPage : Control
writer.WriteStartElement("form"); writer.WriteStartElement("form");
writer.WriteAttributeString("method", "POST"); writer.WriteAttributeString("method", "POST");
}
protected override void RenderContents(XmlWriter writer)
{
foreach (Control control in Controls) foreach (Control control in Controls)
{ {
control.Context = Context; control.Context = Context;
control.Render(writer); control.Render(writer);
} }
}
protected override void RenderEndTag(XmlWriter writer)
{
base.RenderEndTag(writer);
writer.WriteEndElement(); writer.WriteEndElement();
writer.WriteEndElement(); writer.WriteEndElement();