I have a website where I create a textbox multi-line at runtime depending on some selections for example, they specify the number of lines and the width, then I create the textbox and put it in a panel on the next page. My issue is that in the textbox they would like to write something like this:
Company Name
123 Test Avenue
New York, NY 10001
I would like to preserve the formatting, what i mean by this is keeping the next lines as a block, right now if they entered it like that in the textbox it would show like this:
Company Name 123 Test Avenue New York, NY 10001
Is there a way at all to do this with <asp:TextBox/> multi-line ?.
You need to use a control like ckeditor . (Rich text editors for asp.net)
TextArea (asp:textbox with mode="multiline") does not save the formatting, which in your case is <br/>
To persist the rich text into the database you need to think of possible problem in advance.
How to save HTML data in Sql Server
how to save html to a database field
http://forums.asp.net/t/1669475.aspx/1
Related
I am developing a quiz application in ASP.NET. I am using radio buttons to display options like this:
rbOption1.Text = reader["Option1"].ToString();
Now, for a question related to HTML, all the options have only HTML tags in database e.g:
tr td /td td rowspan=”2” /td /tr
I have removed the <> signs otherwise the above example won't render here as text.
When the text for such radio buttons is rendered on webpage, then no text is displayed using RadioButton.Text property.
How can I force the radio buttons to display the tags as stored in database?
You could do something like this:
string TestString = "This is a <Test String>.";
string EncodedString = System.Web.HttpUtility.HtmlEncode(TestString);
More information here: https://www.dotnetperls.com/htmlencode-htmldecode
But the bigger question is why you want to use tables in the first place. It might be a lot simpler to look at a CSS implementation.
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
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 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.
I have few MS word documents which contains text in text boxes. I want to remove those text boxes but keep the data as it. How can i do it ?
I think you can get hold of the text from inside the textboxes using something like ActiveDocument.Shapes(1).TextFrame.TextRange.Text and then you could delete it by doing something like ActiveDocument.Shapes(1).Delete, and after that you'd have to put the text you retrieved from the text box in the relevant part of the document.