问题
I tried to display some text in Textbox(multiple lines) using ASP.NET. But I found that multi-line Textbox (textarea) is HTML encoded, meaning that when I want to display:
a >= b; & c
It will be automatically converted to:
a & gt;= b; & amp; c
which is NOT natural for people to read. So is there any way that I can disable this auto-HTML encoding behavior and just display it naturally in the Textbox?
回答1:
If you are setting the text in the markup (.aspx), then what platon said is correct: .aspx is technically XML, so it has to conform to valid XML which means >
is encoded as >
, etc.
If you are setting the text in code-behind, (for example, textBox.Text = ""
) you could instead use an HtmlControls text area:
System.Web.UI.HtmlControls.HtmlTextArea textBox = new System.Web.UI.HtmlControls.HtmlTextArea();
textBox.Value = "a >= b; & c";
回答2:
As far as I understand, you are talking about the text in the aspx mark up, right? If so, you should not worry. The client side editor will display the text you need, i.e.:
a >= b; & c
来源:https://stackoverflow.com/questions/6651739/how-to-disable-the-textboxs-html-encoding-in-asp-net