This documentation is archived and is not being maintained.

HtmlContainerControl.InnerText Property

Gets or sets the text between the opening and closing tags of the specified HTML server control.

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

public virtual string InnerText { get; set; }
/** @property */
public String get_InnerText ()

/** @property */
public void set_InnerText (String value)

public function get InnerText () : String

public function set InnerText (value : String)

Not applicable.

Property Value

The text between the opening and closing tags of an HTML server control.

Exception typeCondition


There is more than one HTML server control.

- or -

The HTML server control is not a System.Web.UI.LiteralControl or a System.Web.UI.DataBoundLiteralControl.

Use the InnerText property to programmatically modify the text between the opening and closing tags of an HTML server control.

Unlike the InnerHtml property, the InnerText property automatically encodes special characters to and from HTML entities. HTML entities allow you to display special characters, such as the < character, that a browser would ordinarily interpret as having special meaning. The < character would be interpreted as the start of a tag and is not displayed on the page. To display the < character, you would need to use the entity &lt;.

For example, if the InnerText property is set to "<b> Hello </b>", the < and > symbols are converted to &lt; and &gt;, respectively. The rendered output would be: &lt; b &gt; Hello &lt; /b &gt;. The &lt; and &gt; entities would indicate to the browser that these characters are to be displayed on the page. The browser will not detect the <b> tags and display the text in a bold font. The text displayed on the page is: <b> Hello </b>.

To prevent automatic HTML encoding and decoding, use the InnerHtml property.


If there are no child controls, the InnerHtml property contains the value String.Empty.

The following code example demonstrates the HTML encoding service available through the InnerText property.

<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

  protected void Page_Load(Object Src, EventArgs E)
    Message.InnerText = "To make text bold, use the <b> tag.";


<html xmlns="" >
<head runat="server">
    <title>HtmlContainerControl Example</title>
    <form id="form1" runat="server">
    <b><span id="Message" runat="server"></span></b>

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