Click here to Skip to main content
12,401,324 members (50,294 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
Is there any way to display html content in a text box, in a asp.net c# webform?
Posted 20-Jan-13 20:34pm
gavkk1.6K
Comments
   
What do you want to show: rendered context or source HTML code?
—SA
agav 21-Jan-13 3:09am
   
Sorry For wrong question.
I need to show rendered context.
   
I already answered. You should use some non-input element only. Input shows only the raw unformatted text.
—SA
   
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

HI,

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

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

Thanks
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100