System.Web.UI.HtmlControls Namespace HtmlContainerControl Class
Sets or retrieves the text between the start and end tags of the specified HTML server control.
Script |
HtmlContainerControl.InnerText [ = strTxt ] |
This property can only be used programmatically; it cannot be set when declaring the control.
strTxt |
A String object or literal. |
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 InnerText property to programmatically modify the content 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 InnerHtml property, InnerText automatically encodes special characters to and from HTML character entities. HTML entities allow you to display special characters, such as the less than and greater than symbols [ < ... > ] , that a browser would normally interpret as HTML markup, and not display on the page. If these symbols are included in the string value for InnerText, these are internally parsed into the character entities < and >, respectively, and are rendered on the page as such.
To prevent automatic HTML encoding and decoding, use the InnerHtml property instead.
This example demonstrates a simple way to modify the Innertext of an HtmlAnchor control depending on the status of another control.
showhideLink.InnerText = image.Visible ? "Hide Image" : "Show Image";
Show me
This example demonstrates how you can retrieve the InnerText property of one control, in this case an HmlButton control, and assign it as part of the value of another control, in this case the Text property of a Label control.
msg.Text = "Check out other " + ( ( HtmlButton ) sender ).InnerText +
" books at Amazon."
Show me
HtmlContainerControl Members InnerHtml