Html32TextWriter 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将一系列 HTML 3.2 特定字符和文本写入 ASP.NET 服务器控件的输出流。 Html32TextWriter 类提供格式设置功能,ASP.NET 服务器控件在向客户端呈现 HTML 3.2 内容时使用。
public ref class Html32TextWriter : System::Web::UI::HtmlTextWriter
public class Html32TextWriter : System.Web.UI.HtmlTextWriter
type Html32TextWriter = class
inherit HtmlTextWriter
Public Class Html32TextWriter
Inherits HtmlTextWriter
- 继承
- 派生
示例
下面的代码示例演示如何使用派生自 Html32TextWriter 类的类(名为 CustomHtml32TextWriter
)。
CustomHtml32TextWriter
创建遵循 HtmlTextWriter 类建立的模式的两个构造函数,并重写 RenderBeforeContent、RenderAfterContent、RenderBeforeTag和 RenderAfterTag 方法。
using System.IO;
using System.Web.UI;
namespace Examples.AspNet
{
public class CustomHtml32TextWriter : Html32TextWriter
{
// Create a constructor for the class
// that takes a TextWriter as a parameter.
public CustomHtml32TextWriter(TextWriter writer)
: this(writer, DefaultTabString)
{
}
// Create a constructor for the class that takes
// a TextWriter and a string as parameters.
public CustomHtml32TextWriter(TextWriter writer, String tabString)
: base(writer, tabString)
{
}
// Override the RenderBeforeContent method to render
// styles before rendering the content of a <th> element.
protected override string RenderBeforeContent()
{
// Check the TagKey property. If its value is
// HtmlTextWriterTag.TH, check the value of the
// SupportsBold property. If true, return the
// opening tag of a <b> element; otherwise, render
// the opening tag of a <font> element with a color
// attribute set to the hexadecimal value for red.
if (TagKey == HtmlTextWriterTag.Th)
{
if (SupportsBold)
return "<b>";
else
return "<font color=\"FF0000\">";
}
// Check whether the element being rendered
// is an <H4> element. If it is, check the
// value of the SupportsItalic property.
// If true, render the opening tag of the <i> element
// prior to the <H4> element's content; otherwise,
// render the opening tag of a <font> element
// with a color attribute set to the hexadecimal
// value for navy blue.
if (TagKey == HtmlTextWriterTag.H4)
{
if (SupportsItalic)
return "<i>";
else
return "<font color=\"000080\">";
}
// Call the base method.
return base.RenderBeforeContent();
}
// Override the RenderAfterContent method to close
// styles opened during the call to the RenderBeforeContent
// method.
protected override string RenderAfterContent()
{
// Check whether the element being rendered is a <th> element.
// If so, and the requesting device supports bold formatting,
// render the closing tag of the <b> element. If not,
// render the closing tag of the <font> element.
if (TagKey == HtmlTextWriterTag.Th)
{
if (SupportsBold)
return "</b>";
else
return "</font>";
}
// Check whether the element being rendered is an <H4>.
// element. If so, and the requesting device supports italic
// formatting, render the closing tag of the <i> element.
// If not, render the closing tag of the <font> element.
if (TagKey == HtmlTextWriterTag.H4)
{
if (SupportsItalic)
return "</i>";
else
return "</font>";
}
// Call the base method
return base.RenderAfterContent();
}
// Override the RenderBeforeTag method to render the
// opening tag of a <small> element to modify the text size of
// any <a> elements that this writer encounters.
protected override string RenderBeforeTag()
{
// Check whether the element being rendered is an
// <a> element. If so, render the opening tag
// of the <small> element; otherwise, call the base method.
if (TagKey == HtmlTextWriterTag.A)
return "<small>";
return base.RenderBeforeTag();
}
// Override the RenderAfterTag method to render
// close any elements opened in the RenderBeforeTag
// method call.
protected override string RenderAfterTag()
{
// Check whether the element being rendered is an
// <a> element. If so, render the closing tag of the
// <small> element; otherwise, call the base method.
if (TagKey == HtmlTextWriterTag.A)
return "</small>";
return base.RenderAfterTag();
}
}
}
' Create a custom HtmlTextWriter class that overrides
' the RenderBeforeContent and RenderAfterContent methods.
Imports System.IO
Imports System.Web.UI
Namespace Examples.AspNet
Public Class CustomHtml32TextWriter
Inherits Html32TextWriter
' Create a constructor for the class
' that takes a TextWriter as a parameter.
Public Sub New(ByVal writer As TextWriter)
Me.New(writer, DefaultTabString)
End Sub
' Create a constructor for the class that takes
' a TextWriter and a string as parameters.
Public Sub New(ByVal writer As TextWriter, ByVal tabString As String)
MyBase.New(writer, tabString)
End Sub
' Override the RenderBeforeContent method to render
' styles before rendering the content of a <th> element.
Protected Overrides Function RenderBeforeContent() As String
' Check the TagKey property. If its value is
' HtmlTextWriterTag.TH, check the value of the
' SupportsBold property. If true, return the
' opening tag of a <b> element; otherwise, render
' the opening tag of a <font> element with a color
' attribute set to the hexadecimal value for red.
If TagKey = HtmlTextWriterTag.Th Then
If (SupportsBold) Then
Return "<b>"
Else
Return "<font color=""FF0000"">"
End If
End If
' Check whether the element being rendered
' is an <H4> element. If it is, check the
' value of the SupportsItalic property.
' If true, render the opening tag of the <i> element
' prior to the <H4> element's content; otherwise,
' render the opening tag of a <font> element
' with a color attribute set to the hexadecimal
' value for navy blue.
If TagKey = HtmlTextWriterTag.H4 Then
If (SupportsItalic) Then
Return "<i>"
Else
Return "<font color=""000080"">"
End If
End If
' Call the base method.
Return MyBase.RenderBeforeContent()
End Function
' Override the RenderAfterContent method to close
' styles opened during the call to the RenderBeforeContent
' method.
Protected Overrides Function RenderAfterContent() As String
' Check whether the element being rendered is a <th> element.
' If so, and the requesting device supports bold formatting,
' render the closing tag of the <b> element. If not,
' render the closing tag of the <font> element.
If TagKey = HtmlTextWriterTag.Th Then
If SupportsBold Then
Return "</b>"
Else
Return "</font>"
End If
End If
' Check whether the element being rendered is an <H4>.
' element. If so, and the requesting device supports italic
' formatting, render the closing tag of the <i> element.
' If not, render the closing tag of the <font> element.
If TagKey = HtmlTextWriterTag.H4 Then
If (SupportsItalic) Then
Return "</i>"
Else
Return "</font>"
End If
End If
' Call the base method.
Return MyBase.RenderAfterContent()
End Function
' Override the RenderBeforeTag method to render the
' opening tag of a <small> element to modify the text size of
' any <a> elements that this writer encounters.
Protected Overrides Function RenderBeforeTag() As String
' Check whether the element being rendered is an
' <a> element. If so, render the opening tag
' of the <small> element; otherwise, call the base method.
If TagKey = HtmlTextWriterTag.A Then
Return "<small>"
End If
Return MyBase.RenderBeforeTag()
End Function
' Override the RenderAfterTag method to render
' close any elements opened in the RenderBeforeTag
' method call.
Protected Overrides Function RenderAfterTag() As String
' Check whether the element being rendered is an
' <a> element. If so, render the closing tag of the
' <small> element; otherwise, call the base method.
If TagKey = HtmlTextWriterTag.A Then
Return "</small>"
End If
Return MyBase.RenderAfterTag()
End Function
End Class
End Namespace
注解
Html32TextWriter 类是 HtmlTextWriter 类的替代方法。 它将 HTML 4.0 样式属性转换为等效的 HTML 3.2 标记和属性。 它使用 HTML 表标准化属性的传播,如颜色和字体。 ASP.NET 通过检查 HttpBrowserCapabilities 类的 TagWriter 属性自动将此类用于 HTML 3.2 和更早版本的浏览器。 除非创建面向使用 HTML 3.2 标记的设备的自定义页面或控件适配器,否则无需显式创建 Html32TextWriter 类的实例。
有关自定义页面和控件呈现的详细信息,请参阅 演练:开发和使用自定义 Web 服务器控件。
构造函数
Html32TextWriter(TextWriter) |
初始化 Html32TextWriter 类的新实例,该实例使用请求浏览器需要行缩进时在 DefaultTabString 字段中指定的行缩进。 |
Html32TextWriter(TextWriter, String) |
初始化使用指定行缩进的 Html32TextWriter 类的新实例。 |
字段
CoreNewLine |
存储用于此 |
DefaultTabString |
表示单个制表符。 (继承自 HtmlTextWriter) |
DoubleQuoteChar |
表示引号 (“) 字符。 (继承自 HtmlTextWriter) |
EndTagLeftChars |
表示标记元素的左尖括号和斜杠标记(</)。 (继承自 HtmlTextWriter) |
EqualsChar |
表示等号( |
EqualsDoubleQuoteString |
表示一个等号 (=) 和一个双引号 (“) 在字符串 (=) 中一起。 (继承自 HtmlTextWriter) |
SelfClosingChars |
表示标记标记的空格和自右斜杠标记 (/)。 (继承自 HtmlTextWriter) |
SelfClosingTagEnd |
表示自结束标记元素的右斜杠标记和右尖括号(/>)。 (继承自 HtmlTextWriter) |
SemicolonChar |
表示分号(;))。 (继承自 HtmlTextWriter) |
SingleQuoteChar |
表示撇号 (')。 (继承自 HtmlTextWriter) |
SlashChar |
表示斜杠标记(/)。 (继承自 HtmlTextWriter) |
SpaceChar |
表示空格 () 字符。 (继承自 HtmlTextWriter) |
StyleEqualsChar |
表示用于设置样式属性等于值的样式属性的样式等于 ( |
TagLeftChar |
表示标记标记的左尖括号(<)。 (继承自 HtmlTextWriter) |
TagRightChar |
表示标记标记的右尖括号(>)。 (继承自 HtmlTextWriter) |
属性
Encoding |
获取 HtmlTextWriter 对象用于将内容写入页面的编码。 (继承自 HtmlTextWriter) |
FontStack |
获取要呈现的 HTML 的字体信息的集合。 |
FormatProvider |
获取一个对象,该对象控制格式设置。 (继承自 TextWriter) |
Indent |
获取或设置要缩进每行标记开头的制表位数。 (继承自 HtmlTextWriter) |
InnerWriter |
获取或设置写入标记元素的内部内容的文本编写器。 (继承自 HtmlTextWriter) |
NewLine |
获取或设置 HtmlTextWriter 对象使用的行终止符字符串。 (继承自 HtmlTextWriter) |
ShouldPerformDivTableSubstitution |
获取或设置一个布尔值,该值指示是否将 |
SupportsBold |
获取或设置一个布尔值,该值指示请求设备是否支持粗体 HTML 文本。 使用 SupportsBold 属性将粗体文本有条件地呈现到 Html32TextWriter 输出流。 |
SupportsItalic |
获取或设置一个布尔值,该值指示请求设备是否支持斜体 HTML 文本。 使用 SupportsItalic 属性将斜体文本有条件地呈现到 Html32TextWriter 输出流。 |
TagKey |
获取或设置指定标记元素的 HtmlTextWriterTag 值。 (继承自 HtmlTextWriter) |
TagName |
获取或设置正在呈现的标记元素的标记名称。 (继承自 HtmlTextWriter) |
方法
显式接口实现
IDisposable.Dispose() |
有关此成员的说明,请参阅 Dispose()。 (继承自 TextWriter) |