Export (0) Print
Expand All

HtmlElement.InnerHtml Property

Gets or sets the HTML markup underneath this element.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member InnerHtml : string with get, set

Property Value

Type: System.String
The HTML markup that defines the child elements of the current element.

ExceptionCondition
NotSupportedException

Creating child elements on this element is not allowed.

There are several ways to add new elements to an existing HTML page, such as the AppendChild and InsertAdjacentElement methods. Using InnerHtml is often the fastest way to add new content when you have to set many attributes or styles on your new elements.

InnerHtml differs from OuterHtml in that InnerHtml will not include the HTML that represents the object you are calling. See OuterHtml for more information about the difference between these two properties.

Setting InnerHtml destroys any children previously appended to the element. If you retrieve an element from the DOM and then assign new HTML to its parents' InnerHtml property, your reference to that element will be useless, and its behavior when it calls its properties and methods is undefined.

For some elements, setting InnerHtml is not a valid operation. Some HTML tags have no closing tag, such as the IMG tag, and therefore cannot contain nested elements. Some tags, such as the SCRIPT tag, can only contain text content; setting InnerHtml will result in an error. For both types of tags, the CanHaveChildren property will return false. However, you also cannot set InnerHtml on TABLE and TR elements, as assigning malformed HTML to these elements could corrupt the rendering of the document. Use AppendChild or the insertRow and insertCell methods on the unmanaged IHTMLTable interface to add rows and cells to a TABLE.

If you need only to assign text to an element and not HTML markup, use the InnerText property instead.

Assigning a value to InnerHtml will destroy any text values previously assigned using InnerText.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft