简体   繁体   English

文字控制模式之间的差异

[英]Difference between modes of literal control

What is the difference between the passthrough and Transform modes of literal control? 文字控制的passthrough和Transform模式之间有什么区别?

Could you post an example, too? 你也可以发一个例子吗?

There are different Literal Modes Literal.Mode 有不同的Literal Modes Literal.Mode

  1. PassThrough : The contents of the control are not modified. PassThrough:不修改控件的内容。
  2. Encode : The contents of the control are converted to an HTML-encoded string. 编码:控件的内容将转换为HTML编码的字符串。
  3. Transform : Unsupported markup-language elements are removed from the contents of the control. 转换:从控件的内容中删除不支持的标记语言元素。 If the Literal control is rendered on a browser that supports HTML or XHTML, the control's contents are not modified. 如果在支持HTML或XHTML的浏览器上呈现Literal控件,则不会修改控件的内容。

Have a look at this MSDN article http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.literal.mode.aspx 看看这篇MSDN文章http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.literal.mode.aspx

and take a look at this implemented example Use ASP.NET's Literal control to its full potential 并查看这个实现的示例使用ASP.NET的Literal控件充分发挥其潜力

If you decompile System.Web.UI.WebControls.Literal.Render, you get this: 如果你反编译System.Web.UI.WebControls.Literal.Render,你得到这个:

protected internal override void Render(HtmlTextWriter writer)
{
    string text = this.Text;
    if (text.Length != 0)
    {
        if (this.Mode != LiteralMode.Encode)
        {
            writer.Write(text);
        }
        else
        {
            HttpUtility.HtmlEncode(text, writer);
        }
    }
}

This is the same for .NET 2.0 and .NET 4.0. 这与.NET 2.0和.NET 4.0相同。

So whatever the documentation says, there is no difference between Transform (default) and PassThrough. 所以无论文档说什么,Transform(默认)和PassThrough都没有区别。

Please correct me if I'm wrong. 如果我错了,请纠正我。 There are plenty of articles that just repeat the official documentation, but I would like to see a code sample that proves that there is a difference. 有很多文章只是重复官方文档,但我希望看到一个代码示例,证明存在差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM