Difference between modes of literal control

China☆狼群 提交于 2019-12-05 03:24:41
Muhammad Akhtar

There are different Literal Modes Literal.Mode

  1. PassThrough : The contents of the control are not modified.
  2. Encode : The contents of the control are converted to an HTML-encoded string.
  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.

Have a look at this MSDN article 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

If you decompile System.Web.UI.WebControls.Literal.Render, you get this:

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.

So whatever the documentation says, there is no difference between Transform (default) and 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!