Tutorial :How to display HTML in a text Area



Question:

Dear all, I save formatted text (bold, changed in font, style...etc) in an nvarchar(max) field, its for some Description field, on another stage, I want to be able to edit this description, so in the Editing Page, I read the original inoformation, fill it in the fields and wait for the user to change it and save, this is working for all kinds of normal text fields, and also with normal text displayed in a text area, but when I fill the text area with the styled text, it shows the HTML code and not it result, so for instance, it shows:

<span style="font-weight: bold; text-decoration: line-through;">SM</span><span style="background-color: rgb(51, 102, 255);">ART</span><br>  

Instead of a what it should look like, any suggestions on how I can make the textArea (normal asp.net textbox with the mode set to multiline) display the HTML as it should look and not the code??


Solution:1

You can not display HTML result in TextArea/TextBox control. But to display HTML result you have many options.

As Schnalle said, best and the easy way to use an editor. Like tinyMCE or FCKEditor.

In a project I used a div to display and edit HTML content. It allows users to edit, copy, paste, make bold, make italic, .. etc. :

<div runat="server" ID="divContent" contenteditable="true">       Editable Area, set your content here...  </div>  

Maybe you can combine textarea and div to do what you want.


Solution:2

you need a wysiwyg-editor like tinyMCE http://tinymce.moxiecode.com/


Solution:3

If you just want it to display the code, use &lt; as <, and &gt; as >. Eg:

<textarea>  &lt;html&gt;  &lt;body&gt;  &lt;/body&gt;  &lt;/html&gt;  </textarea>  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »