LiteralMode 列舉

定義

指定 Literal 控制項中的內容如何呈現。Specifies how the content in a Literal control is rendered.

public enum class LiteralMode
public enum LiteralMode
type LiteralMode = 
Public Enum LiteralMode
繼承
LiteralMode

欄位

Encode 2

常值控制項的內容是 HTML 編碼。The literal control's contents are HTML-encoded.

PassThrough 1

常值控制項的內容並未修改。The literal control's contents are not modified.

Transform 0

常值控制項的不支援標記語言項目已移除。The literal control's unsupported markup-language elements are removed. 如果常值控制項要呈現在支援 HTML 或 XHTML 的瀏覽器上,控制項的內容就不會加以修改。If the literal control is rendered on a browser that supports HTML or XHTML, the control's contents are not modified.

範例

下列範例示範如何設定 Literal.Mode 屬性。The following example demonstrates how to set the Literal.Mode property. 它一開始會 Encode 在控制項的宣告式語法中設定為。It is initially set to Encode in the declarative syntax for the control. 載入頁面之後,使用者可以按一下按鈕,將 Mode 屬性設定為 PassThroughAfter the page loads, the user can click a button to set the Mode property to PassThrough. 這會導致屬性的內容 Literal.Text 以不同的方式呈現。This causes the contents of the Literal.Text property to render differently.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Literal.Mode Property Example</title>
<script runat="Server">
       
        Sub PassThroughButton_Click(ByVal sender As Object, ByVal e As EventArgs)
   
            Literal1.Mode = LiteralMode.PassThrough
            
            Label1.Text = "The contents of the Literal.Text property " + _
                          "passed through to the browser:"
           
        End Sub
     
   </script>
</head>
<body>
    <form id="Form1" runat="server">
        
        <h3>Literal.Mode Property Example</h3>        
                             
        <asp:Label ID="Label1"
            Text="The HTML-encoded contents of the Literal.Text property:"
            runat="server">     
        </asp:Label><br /><br />
        
        <asp:Literal ID="Literal1"
            Mode="Encode"
            Text= "<b>bold</b><br/><i>italic</i><br/>"          
            runat="server">
        </asp:Literal>
       
        <hr />
       
        <asp:Button ID="PassThroughButton"
            Text="Pass Through Mode"
            OnClick="PassThroughButton_Click"
            runat="server">
        </asp:Button>
         
    </form>
</body>
</html>

備註

列舉型別 LiteralMode (enumeration)代表您可以指定如何呈現控制項內容的模式 LiteralThe LiteralMode enumeration represents the modes that you can specify for how the content in a Literal control is rendered. Literal.Mode屬性會使用這些列舉值來設定屬性內容的行為 Literal.TextThe Literal.Mode property uses these enumeration values to set the behavior of the contents of the Literal.Text property.

如果您指定,則會將 PassThrough 屬性的完整內容 Literal.Text 傳遞至裝置或瀏覽器,而不會進行任何修改。If you specify PassThrough, the entire contents of the Literal.Text property are passed to the device or browser without any modifications. 例如,如果 Literal.Text 屬性包含 <hr> 標記,則會將它傳送至所有裝置和瀏覽器,不論是否受到支援。For example, if the Literal.Text property contains an <hr> tag, it is sent to all devices and browsers regardless of whether it is supported.

如果您指定,則在轉譯 Encode 之前,屬性的內容 Text 會轉換成 HTML 編碼的字串。If you specify Encode, the contents for the Text property are converted into an HTML-encoded string before rendering. 例如,如果 Literal.Text 屬性包含 <hr> 標記,則會將它轉換成,並將其 &lt;hr&gt; 傳送至裝置或瀏覽器。For example, if the Literal.Text property contains an <hr> tag, it will be converted to &lt;hr&gt; and sent to the device or browser.

如果您指定 Transform ,則屬性的呈現行為 Literal.Text 取決於所轉譯的標記類型。If you specify Transform, the rendering behavior of the Literal.Text property depends on the type of markup being rendered. Literal針對支援 HTML 或 XHTML 的裝置或瀏覽器呈現控制項時,指定會 Transform 產生與指定相同的行為 PassThroughWhen the Literal control is rendered for a device or browser that supports HTML or XHTML, specifying Transform produces the same behavior as specifying PassThrough. Literal.Text會針對要求的瀏覽器呈現屬性的所有標記標記和專案。All markup tags and elements for the Literal.Text property are rendered for the requesting browser.

Literal針對 HTML 或 XHTML 以外的標記語言轉譯控制項(例如 WML 或 cHTML)時,您可以使用 Transform 值來移除不支援的標記元素。When the Literal control is rendered for a markup language other than HTML or XHTML, such as WML or cHTML, you can use the Transform value to remove unsupported markup elements. 在此情況下, Literal.Text 不會針對控制項轉譯目標標記語言中不支援之屬性的任何標記語言元素。In this case, any markup-language elements of the Literal.Text property that are not supported in the targeted markup language are not rendered for the control. 例如,如果 Literal.Text 屬性包含 <hr> 標記,則會在將內容傳送至 WML 裝置之前移除標記。For example, if the Literal.Text property contains an <hr> tag, the tag is removed before the content is sent to a WML device. 如果不支援的標記包含內容,則只會移除標記,並將內容傳送至裝置或瀏覽器。If an unsupported tag contains content, only the tag is removed and the content is sent to the device or browser. 例如,如果 Literal.Text 屬性包含內容 <XYZ>Test</XYZ> ,則會在 <XYZ> </XYZ> 將文字 Test 傳送至裝置或瀏覽器時移除和標記。For example, if the Literal.Text property contains the content <XYZ>Test</XYZ>, the <XYZ> and </XYZ> tags are removed while the text Test is sent to the device or browser.

適用於

另請參閱