开发者

How to show `&` in a label control in aspx page

How can I show the text "Replace & with &" in label or textbox in aspx page? When I put Text="Replace & with &" in aspx page, I get output 开发者_开发问答as "Replace & with &"


Use HttpUtility.HtmlEncode("&"); this is always working and the resulting code is more readable.


Replace & with &:

Text = "Replace & with &";

You could also make it work for any character, not just &:

string s = "<";
Text = HttpUtility.HtmlEncode("Replace " + s +
                              " with " + HttpUtility.HtmlEncode(s));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜