如何在 ASP.Net 中禁用文本框的 HTML 编码? [英] How to disable the Textbox's HTML encoding in ASP.Net?

查看:26
本文介绍了如何在 ASP.Net 中禁用文本框的 HTML 编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 ASP.NET 在 Textbox(多行)中显示一些文本.但是我发现多行的Textbox(textarea)是HTML编码的,意思是我想显示的时候:

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

a >= b; & c

会自动转换为:

一个>= b;&放大器;

a & gt;= b; & amp; c

这对于人们阅读来说是不自然的.那么,有什么方法可以禁用这种自动 HTML 编码行为并在文本框中自然地显示它?

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?

推荐答案

如果你在标记(.aspx)中设置文本,那么 platon 说的是正确的:.aspx 在技术上是 XML,所以它必须符合有效的 XML,这意味着 > 被编码为 > 等.

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.

如果您在代码隐藏中设置文本(例如,textBox.Text = ""),您可以改为使用 HtmlControls 文本区域:

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

这篇关于如何在 ASP.Net 中禁用文本框的 HTML 编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆