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.

[Visual Basic]
Public Overridable Property InnerText As String
[C#]
public virtual string InnerText {get; set;}
[C++]
public: __property virtual String* get_InnerText();
public: __property virtual void set_InnerText(String*);
[JScript]
public function get InnerText() : String;
public function set InnerText(String);

Property Value

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

Exceptions

Exception Type Condition
HttpException 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.

Remarks

Use the InnerText property to programmatically modify the contents 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.

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

Example

[Visual Basic, C#, JScript] This example demonstrates the HTML encoding service available through this property.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
    <script language="VB" runat=server>
 
    Sub Page_Load(Src As Object, E As EventArgs)
        Message.InnerText = "To make text bold, use the <b> tag."
    End Sub 'Page_Load
 
  </script>
 
    <body>

          <B><span id="Message" runat=server></span></B>
       
    </body>
 </html>
    

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
    <script language="C#" runat=server>
 
        void Page_Load(Object Src, EventArgs E) {
          Message.InnerText = "To make text bold, use the <b> tag.";
        }
 
    </script>
 
    <body>

          <B><span id="Message" runat=server></span></B>
       
    </body>
 </html>
    

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
    <script language="jscript" runat=server>
 
    function Page_Load(Src: Object, E: EventArgs){
        Message.InnerText = "To make text bold, use the <b> tag."
    }
 
  </script>
 
    <body>

          <B><span id="Message" runat=server></span></B>
       
    </body>
 </html>
    

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

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HtmlContainerControl Class | HtmlContainerControl Members | System.Web.UI.HtmlControls Namespace | InnerHtml

Show: