I am trying to use CKEditor into my ASP.NET Application. I got a good resource as follows
http://www.codeproject.com/Tips/532164/How-to-Integrate-CKEditor-with-ASP-NET
http://www.codeproject.com/Tips/455129/Rich-Text-Editor-with-ASP-NET
I want to set the CKEditor Text without losing its formatting (bold, Italics etc..) into a multiline Textbox. So, I am trying the following code.
string str = this.CKEditor1.Text;
TextBox1.Text = str;
Thus its giving me a html encoded Output as follows
<p>dfgdfgfdgdfgdfgdf<strong>gdf</strong></p>
But I don't want to have those tags around but formatting should be preserved. I tried using HTMLEncode and HTMLDecode, Also used this.CKEditor1.HtmlEncodeOutput = false; but of no avail.
Is there any other way I can save the text as it is without losing formatting into my Textbox?
I know textboxes are not meant for storing formatted html outputs but I have to store this(Comments) along with a formatting in a text box(for History) in my Application. Previously they were using Plain text boxes for both comments and History. Now richtext editing is needed and hence we are tying to go this way. Any other good approaches and suggestions are most welcome.
No, a Textbox cant display formatted values. That is why you have the CKEditor.
You can still store the html formated values in the database and display them (formatted) in for example a Label
Related
I have an ASP.net 4.5 text box with 5 rows. When I save the below data to my table it does not take in consideration that there are line breaks.
Example:
Hello my name is Mike!
How are you?
Please can you help?
When saving this data to my table it of course save it like this below and it will be displayed like this again if I populate my website with this value.
Hello my name is Mike!How are you?Please can you help?
But I want it to be displayed with the line breaks as the way it was written in the first place.
The thing is, I do not want to make use of a custom form item because then the user will be able to copy and paste all html from another website in and I do not want that.
Any idea how this can be done without using a plugin such as below where the user will be able to copy and paste data into?
To populate your text box from the database try;
TextBox1.Text = someText.Replace("\r\n", Environment.NewLine)
For Label
Label1.Text = someText.Replace("\r\n", <br />)
Alternatively you could save the data to your database with the
someText = TextBox1.Text.Replace("\r\n", "<br />")
Although this approach may not be appropriate if the database is also used elsewhere.
I am trying to set the text value of a RichTextBox by Telerik (ie. RadRichTextBox) to a value read from the database.
To set the value I tried the following which is not working "not setting the values"
InputDescription.Text = i._productDescription;
When I display the value of i._productDescription I do get results. So I am sure it is not empty/null and and the text box should have value.
How can I correctly set a text value to the RichTextBox?
Adding text in RadRichTextBox and RadRichTextEditor is done via importing, not with the Text property (although there is FR for this link).
Please refer to the following article which explains how you can import data in RadRichTextEditor: Import/Export | UI for WinForms Documentation.
I have a word template which has a content control placeholder to hold rich text data. The data comes from a sharepoint list (rich text field) and may also include tables in it.
On checking the data from sharepoint list I found it returns me a HTML formatted data. I wish to place this data in the content placeholder with proper formatting.
For example if the data returned is HTML table ( format) I want a table to be created with data populated. Is there any method available to place the data in content control.
I found that third party tool converter at http://html2openxml.codeplex.com/ which is available for conversion, however this appends data to MainDocumentPart not to content control.
Please guide. Thanks in advance.
You could try to use WordDocGenerator, which uses content controls. Then combine it with html2openxml, as discussed here. However, I find the formatting in some cases becomes terrible after adding the html content into your content control--one example is when inserting lists, the bullet points goes out of view when you open the document. I have not tried adding a whole table into a content control.
I want to insert html tag to a Database as a String and retrieve it back. after retrieved it ,I want to bind it in Grid.
as a example
String word = "<h1>This is Heading </h1> \n <h2>This is body</h2> \t This is after tab";
after I bind to the grid it should be
This is Heading(in a big font size)
This is body(in small font) - (tab space) This after tab
However this way is not working. It shows
<h1>This is Heading </h1> \n <h2>This is body</h2> \t This is after tab
word instead of applying real HTML behavior. I tryout with '\' special character removal but it remain same result.
Please help me.
Exactly which control are you using? Most of them will escape html like that for you, and to get it to be written 'as-is' you have to set a property.
If you're using GridView, then you can set the HtmlEncode on your BoundColumn to false.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.htmlencode.aspx
If you're using AutoGenerateColumns, see this SO thread: Prevent HTML encoding in auto-generated GridView columns
Saving into DB is not a problem, you can save directly the string into DB,But when displaying on UI you must use HttpUyility.HtmlEncode(), else it will invite Javascript Hacking.
But if you are entering data from WebPage, make sure Input Validations are turned off Else you will get XSS script attack error.
you can bind your text in literal control it will represent the actual HTML formatted text.
like :
ltrlMsg.Text="<div class=\"Message Success\"> Your Message has been sent successfully! </div>"
or you can bind in you grid too.
My question is that I have extracted data from a file and pushed into a string variable.
I have a FORM created in visual studio having a text box, so I want to display that extracted data in textbox created.
How can achieve this?
You can do it like this:
yourTextBox.Text = yourString;
For a TextBox, it is just
myTextBox.Text = myStringVariable;
But if the data is large, you may want to consider the RichTextBox control instead.
This is all assuming you're using Windows Forms...
string strName="someone";
TextBox1.Text=strName;
If you trim the data to remove the unwanted trailing spaces if there is any.
TextBox1.Text=strName.Trim();