How to disable the Textbox's HTML encoding in ASP.Net?

自作多情 提交于 2020-01-06 05:42:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!