Literal 控件用於在頁面上顯示文本。此文本是可編程的。
注釋:控件不允許您向其內容應用樣式!
AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth, CSSClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled, SkinID, Style, TabIndex, ToolTip, Width
AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls, EnableTheming, EnableVIEwState, ID, NamingContainer, Page, Parent, Site, TemplateControl, TemplateSourceDirectory, UniqueID, Visible
<ASP:Literal
EnableTheming="True|False"
EnableVIEwState="True|False"
ID="string"
Mode="Transform|PassThrough|Encode"
OnDataBinding="DataBinding event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnUnload="Unload event handler"
runat="server"
SkinID="string"
Text="string"
Visible="True|False"
/>
使用 Literal 控件在 Web 窗體頁上顯示靜態文本。與 Label控件不同的是,Literal 不允許您向其內容應用樣式。文本在 Literal 控件中顯示之前並非 HTML 編碼形式。這使得可以在文本中的 Html 標記中嵌入腳本。如果控件的值是由用戶輸入的,請務必要對輸入值進行驗證以防止出現安全漏洞。
下面的示例演示如何使用 Literal 控件顯示靜態文本。
Visual Basic
<%@ Page Language="VB" AutoEventWireup="True" %>
<Html>
<head>
<script runat="server">
Sub ButtonClick(sender As Object, e As EventArgs)
Literal1.Text="Welcome to ASP.Net!!"
End Sub
</script>
</head>
<body>
<form runat="server">
<h3>Literal Example</h3>
<ASP:Literal id="Literal1"
Text="Hello World!!"
runat="server"/>
<br><br>
<ASP:Button id="Button1"
Text="Change Literal Text"
OnClick="ButtonClick"
runat="server"/>
</form>
</body>
</Html>
C#
<%@ Page Language="C#" AutoEventWireup="True" %>
<Html>
<head>
<script runat="server">
void ButtonClick(Object sender, EventArgs e)
{
Literal1.Text="Welcome to ASP.Net!!";
}
</script>
</head>
<body>
<form runat="server">
<h3>Literal Example</h3>
<ASP:Literal id="Literal1"
Text="Hello World!!"
runat="server"/>
<br><br>
<ASP:Button id="Button1"
Text="Change Literal Text"
OnClick="ButtonClick"
runat="server"/>
</form>
</body>
</Html>