开发者

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

开发者 https://www.devze.com 2023-02-17 05:13 出处:网络
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 &

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

精彩评论

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