J
jfkraus
I am writing a custom HtmlText writer because I want to override the
RenderBeforeContent and AfterRenderContent of the <body> tag to insert a
<div> tag around the content of the <body>. I have it working except the
RenderBeforeContent TagKey never finds the <body> tag. What am I missing?
public class CustomHtmlTextWriter : HtmlTextWriter
{
public CustomHtmlTextWriter(TextWriter writer)
: base(writer)
{
}
protected override string RenderBeforeContent()
{
if (base.TagKey == HtmlTextWriterTag.Body)
{
return "<div>";
}
else
{
return base.RenderBeforeContent();
}
}
protected override string RenderAfterContent()
{
if (TagKey == HtmlTextWriterTag.Body)
{
return "</div>";
}
else
{
return base.RenderAfterContent();
}
}
}
public class BasePage : System.Web.UI.Page
{
InterstitialInformation _interstitialInfo;
public BasePage()
{
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter
writer)
{
return new CustomHtmlTextWriter(writer);
}
protected override void Render(HtmlTextWriter writer)
{
if(Response.IsClientConnected)
{
if(_interstitialInfo != null)
{
WidgetsInterstitialHtml4Transitional.ConfigurePage(this,
_interstitialInfo);
(this.Master.FindControl("_interstitialStart") as
Literal).Text =
WidgetsInterstitialHtml4Transitional.PageDivHtmlBegin(_interstitialInfo);
(this.Master.FindControl("_interstitialEnd") as
Literal).Text =
WidgetsInterstitialHtml4Transitional.PageDivHtmlEnd(_interstitialInfo);
}
this.EnsureChildControls();
base.Render(writer);
}
}
RenderBeforeContent and AfterRenderContent of the <body> tag to insert a
<div> tag around the content of the <body>. I have it working except the
RenderBeforeContent TagKey never finds the <body> tag. What am I missing?
public class CustomHtmlTextWriter : HtmlTextWriter
{
public CustomHtmlTextWriter(TextWriter writer)
: base(writer)
{
}
protected override string RenderBeforeContent()
{
if (base.TagKey == HtmlTextWriterTag.Body)
{
return "<div>";
}
else
{
return base.RenderBeforeContent();
}
}
protected override string RenderAfterContent()
{
if (TagKey == HtmlTextWriterTag.Body)
{
return "</div>";
}
else
{
return base.RenderAfterContent();
}
}
}
public class BasePage : System.Web.UI.Page
{
InterstitialInformation _interstitialInfo;
public BasePage()
{
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter
writer)
{
return new CustomHtmlTextWriter(writer);
}
protected override void Render(HtmlTextWriter writer)
{
if(Response.IsClientConnected)
{
if(_interstitialInfo != null)
{
WidgetsInterstitialHtml4Transitional.ConfigurePage(this,
_interstitialInfo);
(this.Master.FindControl("_interstitialStart") as
Literal).Text =
WidgetsInterstitialHtml4Transitional.PageDivHtmlBegin(_interstitialInfo);
(this.Master.FindControl("_interstitialEnd") as
Literal).Text =
WidgetsInterstitialHtml4Transitional.PageDivHtmlEnd(_interstitialInfo);
}
this.EnsureChildControls();
base.Render(writer);
}
}