也许你可以使用
字面意义的
控制并将其内容设置为
输出文档
X文档
.aspx页面的代码
<%@ 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>
.aspx.cs页面的代码
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;
Literal2.Mode = LiteralMode.PassThrough;
Literal3.Mode = LiteralMode.Transform;
Literal1.Text = @"<font size=4 color=red>Literal1 with Encode property example</font><script>alert(""Literal1 with the Encode property"");</script></br></br>";
Literal2.Text = @"<font size=4 color=green>Literal2 with PassThrough property example</font><script>alert(""Literal2 with the PassThrough property"");</script></br></br>";
Literal3.Text = @"<font size=4 color=blue>Literal3 with Encode Transform example</font><script>alert(""Literal3 with the Transform property"");</script></br></br>";
}
}
示例和更多详细信息可在此处找到
http://www.c-sharpcorner.com/uploadfile/puranindia/literal-control-in-Asp-Net/