How to disable the Textbox's HTML encoding in ASP.Net?
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?
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";
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
精彩评论