asp.net.ph

HtmlContainerControl.InnerHtml Property

System.Web.UI.HtmlControls Namespace   HtmlContainerControl Class


Sets or retrieves the HTML content between the start and end tags of the specified HTML server control.

Syntax


Script HtmlContainerControl.InnerHtml [ = strTxt ]

This property can only be used programmatically; it cannot be set when declaring the control.

Property Value


strTxt A String object or literal.

The property takes a string containing a valid combination of text and HTML tags.


Exceptions


Exception Type Condition
HttpException Thrown if
  • There is no HTML server control to set or get the content from.
  • The HTML server control is not a literal control.

Remarks

Use the InnerHtml property to programmatically modify the content, including HTML markup, between the opening and closing tags of an HTML server control.

When setting the property, the given string completely replaces the existing content of the object, except for <html>, <head>, and <title> elements.

Unlike the InnerText property, InnerHtml does not automatically encode special characters to and from HTML character entities, which makes it suitable for including HTML markup. To provide automatic HTML encoding and decoding, use the InnerText property instead.

Example

The below example illustrates using the InnerHtml property to render a bullet list of items in a <span runat="server"> control.

if ( Check1.Checked || Check2.Checked || Check3.Checked ) {
   Message.InnerHtml = "Looks like you prefer: <ul>";
   if ( Check1.Checked ) Message.InnerHtml += "<li>"+Check1.Value;
   if ( Check2.Checked ) Message.InnerHtml += "<li>"+Check2.Value;
   if ( Check3.Checked ) Message.InnerHtml += "<li>"+Check3.Value;
   Message.InnerHtml += "</ul>";
}
else Message.InnerText = "Looks like you don't prefer anything.";

 Show me 

See Also

HtmlContainerControl Members   InnerText Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph