Click here to Skip to main content
12,953,379 members (52,181 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Is there any way to display html content in a text box, in a c# webform?
Posted 20-Jan-13 20:34pm
What do you want to show: rendered context or source HTML code?
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.
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.
Rate this: bad
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:[^].

In .NET, you can do it, if you use System.Web.HttpServerUtility.HtmlEncode:[^].

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.

Rate this: bad
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:[^].

I, for example, like tiny TinyMCE:[^],[^].

You can click here to try it right away:[^].

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

Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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.


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
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,930

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2017
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