HtmlTextWriter.NewLine-Eigenschaft
Ruft die Zeichenfolge für den Zeilenabschluss ab, die vom HtmlTextWriter-Objekt verwendet wird, oder legt diese fest.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Public Overrides Property NewLine As String
'Usage
Dim instance As HtmlTextWriter
Dim value As String
value = instance.NewLine
instance.NewLine = value
public override string NewLine { get; set; }
public:
virtual property String^ NewLine {
String^ get () override;
void set (String^ value) override;
}
/** @property */
public String get_NewLine ()
/** @property */
public void set_NewLine (String value)
public override function get NewLine () : String
public override function set NewLine (value : String)
Eigenschaftenwert
Die vom aktuellen HtmlTextWriter verwendete Zeichenfolge für den Zeilenabschluss.
Hinweise
Die Standardzeichenfolge für den Zeilenabschluss ist ein Wagenrücklauf gefolgt von einem Zeilenvorschub ("\r\n").
Die Zeichenfolge für den Zeilenabschluss wird immer dann in den Ausgabestream geschrieben, wenn eine der WriteLine-Methoden aufgerufen wird. Wenn die NewLine-Eigenschaft auf NULL (Nothing in Visual Basic) festgelegt ist, wird die Standard-Zeilenendemarke verwendet.
Beispiel
Im folgenden Codebeispiel wird die Verwendung einer benutzerdefinierten von der HtmlTextWriter-Klasse abgeleiteten Klasse veranschaulicht, die die FilterAttributes-Methode überschreibt. Beim Aufruf überprüft die FilterAttributes-Überschreibung, ob der Textwriter <label>-Elemente oder <a>-Elemente rendert. Wenn dies der Fall ist, bestimmt die FilterAttributes-Methode, ob für die Beschriftung ein Formatattribut definiert ist. Wenn kein Format definiert ist, legt die FilterAttributes-Methode den Standardwert für das style:color-Attribut auf die Farbe Blau festgelegt. Anschließend fügt die FilterAttributes-Methode mithilfe der NewLine-Eigenschaft einen Zeilenumbruch in das Markuptag ein und schreibt beliebige andere definierte Attribute.
' Override the FilterAttributes method to check whether
' <label> and <anchor> elements contain specific attributes.
Protected Overrides Sub FilterAttributes()
' If the <label> element is rendered and a style
' attribute is not defined, add a style attribute
' and set its value to blue.
If TagKey = HtmlTextWriterTag.Label Then
If Not IsAttributeDefined(HtmlTextWriterAttribute.Style) Then
AddAttribute("style", EncodeAttributeValue("color:blue", True))
Write(NewLine)
Indent = 3
OutputTabs()
End If
End If
' If an <anchor> element is rendered and an href
' attribute has not been defined, call the AddAttribute
' method to add an href attribute
' and set it to http://www.cohowinery.com.
' Use the EncodeUrl method to convert any spaces to %20.
If TagKey = HtmlTextWriterTag.A Then
If Not IsAttributeDefined(HtmlTextWriterAttribute.Href) Then
AddAttribute("href", EncodeUrl("http://www.cohowinery.com"))
End If
End If
' Call the FilterAttributes method of the base class.
MyBase.FilterAttributes()
End Sub
// Override the FilterAttributes method to check whether
// <label> and <anchor> elements contain specific attributes.
protected override void FilterAttributes()
{
// If the <label> element is rendered and a style
// attribute is not defined, add a style attribute
// and set its value to blue.
if (TagKey == HtmlTextWriterTag.Label)
{
if (!IsAttributeDefined(HtmlTextWriterAttribute.Style))
{
AddAttribute("style", EncodeAttributeValue("color:blue", true));
Write(NewLine);
Indent = 3;
OutputTabs();
}
}
// If an <anchor> element is rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href attribute
// and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if (TagKey == HtmlTextWriterTag.A)
{
if (!IsAttributeDefined(HtmlTextWriterAttribute.Href))
{
AddAttribute("href", EncodeUrl("http://www.cohowinery.com"));
}
}
// Call the FilterAttributes method of the base class.
base.FilterAttributes();
}
// Override the FilterAttributes method to check whether
// <label> and <anchor> elements contain specific attributes.
virtual void FilterAttributes() override
{
// If the <label> element is rendered and a style
// attribute is not defined, add a style attribute
// and set its value to blue.
if ( TagKey == HtmlTextWriterTag::Label )
{
if ( !IsAttributeDefined( HtmlTextWriterAttribute::Style ) )
{
AddAttribute( "style", EncodeAttributeValue( "color:blue", true ) );
Write( NewLine );
Indent = 3;
OutputTabs();
}
}
// If an <anchor> element is rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href attribute
// and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if ( TagKey == HtmlTextWriterTag::A )
{
if ( !IsAttributeDefined( HtmlTextWriterAttribute::Href ) )
{
AddAttribute( "href", EncodeUrl( "http://www.cohowinery.com" ) );
}
}
// Call the FilterAttributes method of the base class.
__super::FilterAttributes();
}
// Override the FilterAttributes method to check whether
// <label> and <anchor> elements contain specific attributes.
protected void FilterAttributes()
{
// If the Label tag is being rendered and a style
// attribute is not defined, add a style attribute
// and set its value to blue.
if (get_TagKey().Equals(HtmlTextWriterTag.Label)) {
if (!(IsAttributeDefined(HtmlTextWriterAttribute.Style))) {
AddAttribute("style", EncodeAttributeValue("color:blue",
true));
Write(get_NewLine());
set_Indent(3);
OutputTabs();
}
}
// If an Anchor element is being rendered and an href
// attribute has not been defined, call the AddAttribute
// method to add an href
// attribute and set it to http://www.cohowinery.com.
// Use the EncodeUrl method to convert any spaces to %20.
if (get_TagKey().Equals(HtmlTextWriterTag.A)) {
if (!(IsAttributeDefined(HtmlTextWriterAttribute.Href))) {
AddAttribute("href", EncodeUrl("http://www.cohowinery.com"));
}
}
// Call the FilterAttributes method of the base class.
super.FilterAttributes();
} //FilterAttributes
Plattformen
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
HtmlTextWriter-Klasse
HtmlTextWriter-Member
System.Web.UI-Namespace
WriteLine
TextWriter
NewLine