HtmlTextWriter
am 23.01.2008 02:38:24 von jfkrausI am writing a custom HtmlText writer because I want to override the
RenderBeforeContent and AfterRenderContent of the
tag around the content of the . I have it working except the
RenderBeforeContent TagKey never finds the 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 "
}
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.P ermissions.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(_inter stitialInfo);
(this.Master.FindControl("_interstitialEnd") as
Literal).Text =
WidgetsInterstitialHtml4Transitional.PageDivHtmlEnd(_interst itialInfo);
}
this.EnsureChildControls();
base.Render(writer);
}
}
RenderBeforeContent TagKey never finds the 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 "
";
}
else
{
return base.RenderBeforeContent();
}
}
protected override string RenderAfterContent()
{
if (TagKey == HtmlTextWriterTag.Body)
{
return "
";}
else
{
return base.RenderBeforeContent();
}
}
protected override string RenderAfterContent()
{
if (TagKey == HtmlTextWriterTag.Body)
{
return "
}
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.P ermissions.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(_inter stitialInfo);
(this.Master.FindControl("_interstitialEnd") as
Literal).Text =
WidgetsInterstitialHtml4Transitional.PageDivHtmlEnd(_interst itialInfo);
}
this.EnsureChildControls();
base.Render(writer);
}
}