Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Is there any way to display html content in a text box, in a asp.net c# webform?
Posted
Comments
Sergey Alexandrovich Kryukov 21-Jan-13 2:42am    
What do you want to show: rendered context or source HTML code?
—SA
gavkk 21-Jan-13 3:09am    
Sorry For wrong question.
I need to show rendered context.
Sergey Alexandrovich Kryukov 21-Jan-13 3:14am    
I already answered. You should use some non-input element only. Input shows only the raw unformatted text.
—SA
Sergey Alexandrovich Kryukov 21-Jan-13 3:24am    
Wait a minute! I have a different idea. Maybe, you really need a different kind of component: so called WYSIWYG HTML editor. Please see my Solution 3.
—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
 
Share this answer
 
HI,

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

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


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

Thanks
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900