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));
精彩评论