This documentation is archived and is not being maintained.

HtmlTextWriter.NewLine Property

Gets or sets the line terminator string used by the current HtmlTextWriter.

[Visual Basic]
Overrides Public Property NewLine As String
[C#]
public override string NewLine {get; set;}
[C++]
public: __property String* get_NewLine();
public: __property void set_NewLine(String*);
[JScript]
public override function get NewLine() : String;
public override function set NewLine(String);

Property Value

The line terminator string used by the current HtmlTextWriter.

Remarks

The default line terminator string is a carriage return, followed by a line feed ("\r\n").

The line terminator string is written to the text stream whenever one of the WriteLine methods is called. If the NewLine property is set to a null reference, the default new line character is used.

Example

[Visual Basic, C#, C++] The following example shows a custom HtmlTextWriter class that overrides the FilterAttributes method. When called, the FilterAttributes method checks whether the text writer renders any <label> or <a> HTML elements. If so, it determines whether a style attribute is defined for the label. If no style is defined, it sets the default value for the style:color attribute to blue. It then uses the NewLine property to insert a line break in the HTML tag and writes any other defined attributes.

[Visual Basic] 
' Override the FilterAttributes method to filter for 
' an HTML label and an anchor elements' attributes.

Protected Overrides Sub 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 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 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 TagKey = HtmlTextWriterTag.A Then
      If Not IsAttributeDefined(HtmlTextWriterAttribute.Href) Then
         AddAttribute("href", EncodeUrl("http://www.cohowinery.com"))
      End If
   End If
   ' Call the base class's FilterAttributes method
   ' to ensure that calling this custom HtmlTextWriter
   ' includes functionality for all other HTML elements.
   MyBase.FilterAttributes()
End Sub 'FilterAttributes   

[C#] 
// Override the FilterAttributes method to filter for 
// an HTML label and an anchor elements' attributes.

protected override 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(TagKey == HtmlTextWriterTag.Label)
   {
      if(!IsAttributeDefined(HtmlTextWriterAttribute.Style))
      {
         AddAttribute("style", EncodeAttributeValue("color:blue", true));
         Write(NewLine);
         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(TagKey == HtmlTextWriterTag.A)
   {
      if(!IsAttributeDefined(HtmlTextWriterAttribute.Href))
      {
         AddAttribute("href", EncodeUrl("http://www.cohowinery.com"));
      }
   }
   // Call the base class's FilterAttributes method
   // to ensure that calling this custom HtmlTextWriter
   // includes functionality for all other HTML elements.
   base.FilterAttributes();
}

[C++] 
// Override the FilterAttributes method to filter for
// an HTML label and an anchor elements' 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 (TagKey == HtmlTextWriterTag::Label) {
      if (!IsAttributeDefined(HtmlTextWriterAttribute::Style)) {
         AddAttribute(S"style", EncodeAttributeValue(S"color:blue", true));
         Write(NewLine);
         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 (TagKey == HtmlTextWriterTag::A) {
      if (!IsAttributeDefined(HtmlTextWriterAttribute::Href)) {
         AddAttribute(S"href", EncodeUrl(S"http://www.cohowinery.com"));
      }
   }
   // Call the base class's FilterAttributes method
   // to ensure that calling this custom HtmlTextWriter
   // includes functionality for all other HTML elements.
   __super::FilterAttributes();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HtmlTextWriter Class | HtmlTextWriter Members | System.Web.UI Namespace

Show: