Sri Reddy
Sri Reddy

Reputation: 7012

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 &"

Upvotes: 1

Views: 1292

Answers (2)

Mark Byers
Mark Byers

Reputation: 838566

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));

Upvotes: 1

Felice Pollano
Felice Pollano

Reputation: 33262

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

Upvotes: 3

Related Questions