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.
Script |
HtmlContainerControl.InnerHtml [ = strTxt ] |
This property can only be used programmatically; it cannot be set when declaring the control.
strTxt |
A String object or literal. |
The property takes a string containing a valid combination of text and HTML tags.
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.
|
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.
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
HtmlContainerControl Members InnerText