You can use the Literal control as a container for other content on a Web page. The Literal control is most commonly used to dynamically add content to a Web page. Simply put, the HTML code can be written to the Literal control and presented directly.
First, common literal properties
Property |
Description |
Text |
Specifies the text to display in the Literal control. In the user's browser, this will appear as HTML. |
Mode |
Specifies how the control handles the markup that is added to it. |
Ii. Basic Usage
Front desk literaltest.aspx
Copy Code code as follows:
<asp:literal id= "Literal1" runat= "Server" ></asp:Literal>
Backstage LiteralTest.aspx.cs
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
string table = "<table cellspacing=\" 0\ "cellpadding=\ 3\" border=\ "1\" ><tr><td style=\ "border:1px;\" >hello world</td></tr></table> ";
This. Literal1.text = table;
}
Three, literal and label difference
A 1.Literal control is similar to a Label control, but the Literal control does not allow styles to be applied to the displayed text. You can programmatically control the text that is displayed in the control by setting the Text property.
The 2.Literal control does not produce any extra HTML code, and the label control generates a span label.