Click to Rate and Give Feedback
MSDN
MSDN Library

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
HtmlContainerControl..::.InnerHtml Property

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

Namespace:  System.Web.UI.HtmlControls
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
<BrowsableAttribute(False)> _
Public Overridable Property InnerHtml As String
Visual Basic (Usage)
Dim instance As HtmlContainerControl
Dim value As String

value = instance.InnerHtml

instance.InnerHtml = value
C#
[BrowsableAttribute(false)]
public virtual string InnerHtml { get; set; }
Visual C++
[BrowsableAttribute(false)]
public:
virtual property String^ InnerHtml {
    String^ get ();
    void set (String^ value);
}
JScript
public function get InnerHtml () : String
public function set InnerHtml (value : String)
ASP.NET
<asp:HtmlContainerControl InnerHtml="String" />

Property Value

Type: System..::.String
The HTML content between opening and closing tags of an HTML server control.
ExceptionCondition
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.

Use the InnerHtml property to programmatically modify the contents between 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 noteCaution:

Because 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. For more information, see Security and User Input.

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

NoteNote:

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

The following code example demonstrates how to use the InnerHtml property to dynamically set a text message.

Visual Basic
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    Message.InnerHtml = Server.HtmlEncode("Welcome! You accessed this page at: " & DateTime.Now)

  End Sub

</script>

<html  >
<head id="Head1" runat="server">
    <title>HtmlContainerControl Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <span id="Message" runat="server"></span>    
    </div>
    </form>
</body>
</html>    

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  protected void Page_Load(object sender, EventArgs e)
  {
    Message.InnerHtml = Server.HtmlEncode("Welcome! You accessed this page at: " + DateTime.Now);
  }
</script>

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

JScript
<%@ Page Language="JScript" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  function Page_Load(Src: Object, E: EventArgs)
  {
    Message.InnerHtml = Server.HtmlEncode("Welcome! You accessed this page at: " + DateTime.Now)
  }

</script>

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker