displaying email body as html in c# textbox - c#

I am imitating my email client on a asp page. I have a gridview that displays things like from,subject,attachments, and the body. The body is html. When I view it in the grid view and set htmlencode= 'false' i can see it correctly. However, I want to the display it inside a textbox, so it can edit and forward it or reply.
Any ideas?
Thanks,

Load the HTML into a rich text editor to enable to user to edit it - be aware that most rich text editors out there are not designed to create email safe HTML and they will require a substantial amount of tweaking if you are going to support more than the most basic formatting.
Some example rich text editors:
http://ajaxcontroltoolkit.codeplex.com/
http://www.freetextbox.com/

Look into using a WYSIWYG (What You See Is What You Get) text editor like Cute Editor

you need to use an HTML Editor / TextBox, we use DevExpress components, very high quality but not free, there are also alternatives like Telerik or Infragistics and also free alternatives... see here: Best Free available wysiwyg html editor

Try this...
You can-t display html in textbox but you can get the source code.I am using this:) click here

You can try dinamycly add html code to page:
<div runat="server" id="myDiv">
</div>
and then set its InnerHtml property from the code-behind:
myDiv.InnerHtml = "your html here";
but with this way you cannot edit it...

if you are using Devexpress Controls,
you can use ASPxHTMLEditor.
It works exactly as your requirement is.

Related

Textboxes in Asp.Net using C#?

How to get different colors of text in a text box in ASP.NET when words printed in the Text Box are dynamic using database? Please help! There is rich text box for this purpose in Window Form but what about the web forms?
Standard ASP.NET TextBox renders as <input type="text"> which does not support styles for individual characters.
You can use a 3rd party tool or, at a very basic you can use DIV with contenteditable set to true:
Here's a small demo: http://jsfiddle.net/Pr9mm/
If you are looking for a rich-text box to use - try the HTMLEditor in the AjaxControlToolkit. It is essentially the same functionality. Just make sure to put a sanitizer on it to avoid XSS problems.
Check the accepted answer for this question. Eventhough it is for gridview the same logic could be used for textbox also. Hope this helps you in right direction.
Consider using the HtmlEditorExtender from the ajax control toolkit. You can also configure how the textbox looks.

Rich textbox that displays html like a web browser control

I am displaying text in a rich textbox and i want it to show the html formatting on the text. Is there a way to make a rich textbox display html.
If you push the button on the following link you will see how my out put displays, i would like it done in a rich textbox.
http://neil.fraser.name/software/diff_match_patch/svn/trunk/demos/demo_diff.html
Is there a way to build a rich textbox that can display html???
RTF encoding is different from HTML.
If not, then you need to write your own HTML to RTF converter or find something similar.
Writing Your Own RTF Converter. This guy gives a great breakdown of how the program works along with details of the conversion.
An Extended richtextbox control, Check this out. It may solve your solution

How to change the input language of CKEditor with ASP.Net C#

I am using CKEditor in my project and I need to set its input language as Farsi.
I already done this with some textboxes and textareas with a .js file named "FarsiType.js".
FarsiType.js is here : http://www.farsitype.ir/FarsiType.js
When we add an attribute lang="fa" with textbox control its input will be change to Farsi language.
like this :
<asp:TextBox runat="server" ID="tr" lang="fa" dir="rtl"/>
I need to set Farsi in put for CKEditor too. So how do i set its text input to Farsi language ?
Please help me
Default CKEditor language
Default language is used in case no language is set using config.language option and the editor is not able to use the user language.
In order to change default language use the following command:
config.defaultLanguage = 'fa';
For more details visit:http://docs.cksource.com/Talk:CKEditor_3.x/Developers_Guide
The only think you could change to Farsi is the CKEditor's face, buttons title and the text direction. The reason is FarsiType.js is workin on fields and textareas. If you look closely to CKEditor in developer tools, you will see in CKEditor you are typing in the body inside an iFrame and then when you submit the form it will transfer the content to your textarea. Its not possible to apply http://www.farsitype.ir/FarsiType.js to CKEditor unless you access the iframe before load and add the script inside the iframe.

highlight a word in textarea in ASP.NET using C#

I have a TextArea control in my ASP.NET page which gets populated with a paragraph containing multiple sentences from the database. After this data gets populated in the TextArea control, I need to search for a few words in them and highlight them in different color. The words that I need to highlight are present inside a table in the database.
My question is : How do I highlight the selected words in a TextArea control using C#?
Please help. Thank you.
The HTML <textarea> tag doesn't contain the ability to add any text formatting. If you want to highlight a portion of your text, then you'll need to display it within a <div>, <span> or some other HTML element.
If you need to make the text editable and still highlight portions of it, then you could use a WYSIWYG HTML editor, such as the jHtmlArea Free, Open Source jQuery plugin.
Shameless Plug: jHtmlArea is a jQuery plugin I created a while back to fit a need I had for a light weight, easily extensible WYSIWYG HTML editor.
You can look into the DynaCloud jQuery plugin, or CodeMirror. Both provide some functionality for highlighting text.
http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
http://codemirror.net/

Safe HTML in ASP.NET Controls

Im sure this is a common question...
I want the user to be able to enter and format a description.
Right now I have a multiline textbox that they can enter plain text into. It would be nice if they could do a little html formatting. Is this something I am going to have to handle? Parse out the input and only validate if there are "safe" tags like <ul><li><b> etc?
I am saving this description in an SQL db. In order to display this HTML properly do I need to use a literal on the page and just dump it in the proper area or is there a better control for what I am doing?
Also, is there a free control like the one on SO for user input/minor editing?
Have a look at the AntiXSS library. The current release (3.1) has a method called GetSafeHtmlFragment, which can be used to do the kind of parsing you're talking about.
A Literal is probably the correct control for outputting this HTML, as the Literal just outputs what's put into it and lets the browser render any HTML. Labels will output all the markup including tags.
The AJax Control Toolkit has a text editor.
Also, is there a free control like the
one on SO for user input/minor
editing?
Stackoverflow uses the WMD control and markdown as explained here:
https://blog.stackoverflow.com/2008/09/what-was-stack-overflow-built-with/
You will need to check what tags are entered to avoid Cross side scripting attacks etc. You could use a regex to check that any tags are on a 'whitelist' you have and strip out any others.
You can check out this link for a list of rich text editors.
In addition to the other answers, you will need to set ValidateRequest="false" in the #Page directive of the page that contains the textbox. This turns off the standard ASP.NET validation that prevents HTML from being posted from a textbox. You should then use your own validation routine, such as the one #PhilPursglove mentions.

Categories