zoukankan      html  css  js  c++  java
  • Literal Control in Asp.net

    The Literal control is used to display text; that is, it renders static text on a Web page without adding additional HTML tags. It passes content directly to the client browser unless you use the Mode property to encode the content. 

    For the above reason, in some special place, we can use it freely, especially use the css class in our sorce

    Here copy some sorce code from other web

    Code for .aspx page

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!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>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Literal ID="Literal1" runat="server" />
            <asp:Literal ID="Literal2" runat="server" />
            <asp:Literal ID="Literal3" runat="server" />
        </div>
        </form>
    </body>
    </html>

    Code for .aspx.cs page


    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Literal1.Mode = LiteralMode.Encode;
            Literal1.Mode = LiteralMode.PassThrough;
            Literal1.Mode = LiteralMode.Transform;

            Literal1.Text = @"<font size=4 color=red>Literal1 with Encode property example</font><script>alert(""Literal with Encode property"");</script></br></br>";

            Literal2.Text = @"<font size=4 color=green>Literal2 with PassThrough property example</font><script>alert(""Literal with PassThrough property"");</script></br></br>";

            Literal3.Text = @"<font size=4 color=blue>Literal3 with Encode Transform example</font><script>alert(""Literal with Transform property"");</script></br></br>";
        }
    }

    Love it, and you live without it
  • 相关阅读:
    Word 2007 测试
    全硬盘安装Win Vista 6000 RTM方法(转)
    Javascript 解析,格式化日期 (转)
    转:使用hgfs实现vmare文件传输一法,无需任何网络相关设置
    配置和运行版本验证测试(转自msdn)
    TFS错误一则(資料集 'IterationParam' 的查詢執行失敗)
    ghostdoc 1.9.5 for vista install
    January 2007 Community Technology Preview 1 安装
    Changing to a friendly Team Foundation Server Name (舶来品)
    命令行使用小结
  • 原文地址:https://www.cnblogs.com/tomclock/p/13412553.html
Copyright © 2011-2022 走看看