literal控件
這就是literal控件
用于在網頁上呈現可能出現語言標記的文本的解決方案.
此控件有一個叫LiteralMode的枚舉屬性:Encode,Passthrough,Transform.
Encode屬性用于將文本進行HTML編碼后原樣顯示到瀏覽器上。
Passthrough屬性用于將Text屬性直接傳送給瀏覽器,不經過任何編碼或修改。
Transform屬性用于移除不受支持的標記元素,在這種情況下,目標標記語言不支持的所有元素都不會呈現(移除標記,保留內容) 。
注意:
如果顯示Literal控件的設備或瀏覽器支持HTML或XHTML語言,那么passthrough和Transform屬性會顯示相同的結果。如果顯示Literal控件的設備或瀏覽器并不支持HTML或XHTML,例如手機上的瀏覽器,那么指定transform值后,literal控件會在顯示文本前將不受支持的標記移除,而保留內容。(關于這一點,因為本為沒有做過手機開發,所以無法驗證)
以下為一個在PC瀏覽器上的小示例,此例中,指定passthrough或Transform值會顯示相同的結果。
?以下為頁面代碼
<%@?Page?Language="C#"?AutoEventWireup="true"?CodeFile="T_Literal.aspx.cs"?Inherits="T_Literal"?%>
<!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?runat="server">
????<title>無標題頁</title>
</head>
<body>
????<form?id="form1"?runat="server">
????<div>
????????
????????<asp:RadioButton?ID="radioEncode"?runat="server"?GroupName="LiteralMode"?Checked="true"?Text=Encode?AutoPostBack=true?/>
????????<asp:RadioButton?ID="radioPassthrough"?runat="server"?GroupName="LiteralMode"?Text="Passthrough"?AutoPostBack="true"?/>
????????<asp:RadioButton?ID="radioTransform"?runat="server"?Text="Transform"?AutoPostBack="true"?GroupName="LiteralMode"?/><br?/><hr/><br?/>
????????<asp:Literal?ID="Literal1"?runat="server"></asp:Literal>
????????</div>
????</form>
</body>
</html>
?以下為隱藏代碼
using?System.Data;
using?System.Configuration;
using?System.Collections;
using?System.Web;
using?System.Web.Security;
using?System.Web.UI;
using?System.Web.UI.WebControls;
using?System.Web.UI.WebControls.WebParts;
using?System.Web.UI.HtmlControls;
public?partial?class?T_Literal?:?System.Web.UI.Page
{
????protected?void?Page_Load(object?sender,?EventArgs?e)
????{
????????Literal1.Text?=?"this?<hr><b>text</b><a>aaa</a><ccc>?is?inserted?dynamically";
????????if?(radioEncode.Checked)
????????{
????????????Literal1.Mode?=?LiteralMode.Encode;
????????}
????????if?(radioPassthrough.Checked)
????????{
????????????Literal1.Mode?=?LiteralMode.PassThrough;
????????}
????????if?(radioTransform.Checked)
????????{
????????????Literal1.Mode?=?LiteralMode.Transform;
????????}
????}
}
?
轉載于:https://www.cnblogs.com/cykevin/archive/2008/12/08/1350682.html
總結
- 上一篇: Flash中的“插入关键帧”和“插入空白
- 下一篇: 使用PostBackUrl与Server