HtmlTextWriter 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 HtmlTextWriter 类的新实例。
重载
HtmlTextWriter(TextWriter) |
初始化使用默认制表符字符串的 HtmlTextWriter 类的新实例。 |
HtmlTextWriter(TextWriter, String) |
使用指定的制表符字符串字符初始化 HtmlTextWriter 类的新实例。 |
HtmlTextWriter(TextWriter)
初始化使用默认制表符字符串的 HtmlTextWriter 类的新实例。
public:
HtmlTextWriter(System::IO::TextWriter ^ writer);
public HtmlTextWriter (System.IO.TextWriter writer);
new System.Web.UI.HtmlTextWriter : System.IO.TextWriter -> System.Web.UI.HtmlTextWriter
Public Sub New (writer As TextWriter)
参数
- writer
- TextWriter
呈现标记内容的 TextWriter 实例。
示例
下面的代码示例演示如何使用 HtmlTextWriter(TextWriter) 构造函数创建名为 的StyledLabelHtmlWriter
自定义HtmlTextWriter对象。
MyPage
当客户端浏览器请求从 Page 类派生的自定义类时,它使用 StyledLabelHtmlWriter
类将其内容呈现到输出流。
// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the StyledLabelHtmlWriter class to render its content.
public ref class MyPage: public Page
{
protected:
virtual HtmlTextWriter^ CreateHtmlTextWriter( TextWriter^ writer ) override
{
return gcnew HtmlStyledLabelWriter( writer );
}
};
// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the HtmlStyledLabelWriter class to render its content.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class MyPage : Page
{
protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
{
return new HtmlStyledLabelWriter(writer);
}
}
' A custom class that overrides the CreateHtmlTextWriter method.
' This page uses the StyledLabelHtmlWriter to render its content.
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class MyPage
Inherits Page
Protected Overrides Function CreateHtmlTextWriter(ByVal writer As TextWriter) As HtmlTextWriter
Return New HtmlStyledLabelWriter(writer)
End Function 'CreateHtmlTextWriter
End Class
注解
HtmlTextWriter当需要缩进行时,HtmlTextWriter(TextWriter)构造函数的重载使用 DefaultTabString 常量。 它调用 HtmlTextWriter(TextWriter, String) 重载来初始化新实例。
另请参阅
适用于
HtmlTextWriter(TextWriter, String)
使用指定的制表符字符串字符初始化 HtmlTextWriter 类的新实例。
public:
HtmlTextWriter(System::IO::TextWriter ^ writer, System::String ^ tabString);
public HtmlTextWriter (System.IO.TextWriter writer, string tabString);
new System.Web.UI.HtmlTextWriter : System.IO.TextWriter * string -> System.Web.UI.HtmlTextWriter
Public Sub New (writer As TextWriter, tabString As String)
参数
- writer
- TextWriter
呈现标记内容的 TextWriter。
- tabString
- String
用于呈现行缩进的字符串。
示例
下面的代码示例演示如何使用 HtmlTextWriter(TextWriter) 构造函数创建名为 的StyledLabelHtmlWriter
自定义HtmlTextWriter对象。
MyPage
当客户端浏览器请求从 Page 类派生的自定义类时,它使用 StyledLabelHtmlWriter
类将其内容呈现到输出流。
// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the StyledLabelHtmlWriter class to render its content.
public ref class MyPage: public Page
{
protected:
virtual HtmlTextWriter^ CreateHtmlTextWriter( TextWriter^ writer ) override
{
return gcnew HtmlStyledLabelWriter( writer );
}
};
// A custom class that overrides its CreateHtmlTextWriter method.
// This page uses the HtmlStyledLabelWriter class to render its content.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class MyPage : Page
{
protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
{
return new HtmlStyledLabelWriter(writer);
}
}
' A custom class that overrides the CreateHtmlTextWriter method.
' This page uses the StyledLabelHtmlWriter to render its content.
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class MyPage
Inherits Page
Protected Overrides Function CreateHtmlTextWriter(ByVal writer As TextWriter) As HtmlTextWriter
Return New HtmlStyledLabelWriter(writer)
End Function 'CreateHtmlTextWriter
End Class
注解
HtmlTextWriter当需要缩进行时,HtmlTextWriter(TextWriter, String)构造函数的重载使用 tabString
。 它调用 TextWriter.TextWriter(IFormatProvider) 基构造函数来初始化新实例。