NewLine Property
Collapse the table of content
Expand the table of content

HtmlTextWriter.NewLine Property

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

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

public override string NewLine { get; set; }
/** @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)

Not applicable.

Property Value

The line terminator string used by the current HtmlTextWriter.

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

The line terminator string is written to the output stream whenever one of the WriteLine methods is called. If the NewLine property is set to a null reference (Nothing in Visual Basic), the default new line character is used.

The following code example shows how to use a custom class, derived from the HtmlTextWriter class, that overrides the FilterAttributes method. When called, the FilterAttributes override checks whether the text writer renders any <label> or <a> elements. If so, the FilterAttributes method determines whether a style attribute is defined for the label. If no style is defined, the FilterAttributes method sets the default value for the style:color attribute to blue. The FilterAttributes method then uses the NewLine property to insert a line break in the markup tag and writes any other defined attributes.

// 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.      
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

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2016 Microsoft