HtmlTextWriter

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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top