Export (0) Print
Expand All

HtmlContainerControl.InnerHtml Property

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

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

Property Value

The HTML content between 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 InnerHtml property to programmatically modify the contents within the opening and closing tags of an HTML server control.

The InnerHtml property does not automatically encode 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 InnerHtml property is set to "<b> Hello </b>", the < and > characters are not converted to &lt; and &gt;, respectively. The rendered output would still be: <b> Hello </b>. The browser will detect the <b> tags and display the text, Hello, in a bold font.

CAUTION   Since the text is not HTML encoded, it possible to embed script within HTML tags in the text. If this property is set dynamically using user input, be sure to validate the value to reduce security vulnerabilities.

To provide automatic HTML encoding and decoding, use the InnerText property.

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

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the InnerHtml property to dynamically set a text message.

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

<html>
    <script language="VB" runat=server>
    Sub Page_Load(Src As Object, E As EventArgs)
        Message.InnerHtml = "Welcome! You accessed this page at: " & DateTime.Now
    End Sub 'Page_Load 
  </script>
 
    <body>

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

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

<html>
    <script language="C#" runat=server>
 
        void Page_Load(Object Src, EventArgs E) {
          Message.InnerHtml = "Welcome! You accessed this page at: " + DateTime.Now;
        }
 
    </script>
 
    <body>

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

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

<html>
    <script language="jscript" runat=server>
    function Page_Load(Src: Object, E: EventArgs){
        Message.InnerHtml = "Welcome! You accessed this page at: " + DateTime.Now
    }
  </script>
 
    <body>

          <span id="Message" runat=server></span>
       
    </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 | InnerText

Show:
© 2014 Microsoft