简体   繁体   中英

literal control showing character encoding

I have a problem displaying html entities in a literal control in asp.net.

Before I pass my content to a literal control I encode the characters eg £ to £ but when it gets displayed in the page it displays £ instead of £ . I checked the source and it is not encoding the html entity eg &amppound; but displaying it as plain text.

I have tried removing the htmlencode at the backend and adding mode="encode" on the literal control but I get the same results.

Does anyone know why this happens?

I know I can use a label control but surely theres a better way? I do not like the html format literal control gives.

Given a literal, lt, you should not HtmlEncode, and set

lt.Mode = LiteralMode.PassThrough;
lt.Text = "&pound";

or

<asp:Literal runat="server" ID="lt" Mode="PassThrough">&pound;</asp:Literal>

hope this will help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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