在文本框中显示html内容 [英] display html content in a textbox

查看:517
本文介绍了在文本框中显示html内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在asp.net c#webform中的文本框中显示html内容?

Is there any way to display html content in a text box, in a asp.net c# webform?

推荐答案

当然。如果将HTML代码放在输入控件中( TextBox 呈现为 HTML 输入元素),则可以显示HTML源代码,如果您将此代码复制到该值。



如果要在某些非输入控件中显示源HTML代码,它将显示作为呈现的HTML。如果要显示原始源代码,只需要使用字符实体转义所有HTML标记。以下是它们的列表:

http://www.w3.org /TR/html4/sgml/entities.html [ ^ ]。



在.NET中,你可以这样做,如果你使用 System.Web.HttpServerUtility.HtmlEncode http://msdn.microsoft.com/ en-us / library / system.web.httpserverutility.htmlencode.aspx [ ^ ]。



好​​的,我明白了。问题很模糊(请参阅我对该问题的评论)。我可以看到它的另一个可能含义。也许你的意思是在 TextBox 中显示呈现的HTML。不,你不能这样做。使用一些非输入元素。



-SA
Of course. If you put HTML code in an input control (your TextBox is rendered as HTML input element), you can show the HTML source code, if you copy this code as is to the value.

If you want to show source HTML code in some non-input control, it will be shown as rendered HTML. If you want to show raw source code, you just need to escape all HTML markup with character entities. Here is the list of them:
http://www.w3.org/TR/html4/sgml/entities.html[^].

In .NET, you can do it, if you use System.Web.HttpServerUtility.HtmlEncode: http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmlencode.aspx[^].

OK, I see. The question is very ambiguous (please see my comment to the question). I can see yes another possible meaning of it. Perhaps you mean to show rendered HTML in TextBox. No, you cannot do it. Use some non-input element.

—SA


感谢您澄清问题。我不确切地知道你的目标,但是你可能还需要另一种选择。



即使HTML输入不允​​许你原则上显示渲染的HTML ,但简单的非输入元素将呈现它但不允许编辑,您可能需要构建更复杂的HTML控件,它可以做到这一点。这些控件称为WYSIWYG HTML编辑器。请参阅:

http://en.wikipedia.org/wiki/HTML_editor [< a href =http://en.wikipedia.org/wiki/HTML_editortarget =_ blanktitle =New Window> ^ ]。



我,比如小TinyMCE:

http://en.wikipedia.org/ wiki / TinyMCE [ ^ ],

http://www.tinymce.com/ [ ^ ]。



您可以点击此处立即试用: http://www.tinymce.com/tryit/full.php [ ^ ]。



你可以Google for a类似解决方案的数量。您可以轻松地将它们嵌入您的网站。



-SA
Thank you for clarification of the question. I don''t know your goals exactly, but there is another option you might need.

Even though the HTML input will not allow you to show rendered HTML in principle, but simple non-input element will render it but won''t allow editing, you may need to build much more complex HTML control which can do it. Such controls are called WYSIWYG HTML editors. Please see:
http://en.wikipedia.org/wiki/HTML_editor[^].

I, for example, like tiny TinyMCE:
http://en.wikipedia.org/wiki/TinyMCE[^],
http://www.tinymce.com/[^].

You can click here to try it right away: http://www.tinymce.com/tryit/full.php[^].

You can Google for a number of similar solutions. You can easily embed them in your site.

—SA


HI,


您可以通过在页面中将validation属性设置为false来实现,例如:





You can do it by making the validation property to false in the page like:

<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="Availability.aspx.cs"

    Inherits="Availability" %>





但是将HTML数据存储在数据库中会产生一些安全问题。为了避免这种情况,你可以使用HTMLEncode()和HTMLDecode()技术。



谢谢



But storing the HTML data in the database creates some security problems. To avoid that you can use HTMLEncode() and HTMLDecode() Technique.

Thanks


这篇关于在文本框中显示html内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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