Asked by:
Text in multiple lines

Question
-
User546194788 posted
In my asp.net project, there is a multiple line text box to let user input comments.
If user input a comment like below.
Thank you for your fax.
I'll reissue a check to you.
If you have any question, please call me at xxx-xxx-xxxx.
This comment will save as varchar into a SQL server table.
The problem is that once review this comment, three lines text will display like one line text as below.
Thank you for your fax.I'll reissue a check to you.If you have any question, please call me at xxx-xxx-xxxx.
How to fix it?
Thursday, October 11, 2018 5:48 PM
All replies
-
User2103319870 posted
aspfun
his comment will save as varchar into a SQL server table.
The problem is that once review this comment, three lines text will display like one line text as below.
If you are using a normal textbox then I would suggest to use a RichTextEditor control instead of normal textbox. This will save the line break and other formatting options you apply on the text
Some controls you can use
Thursday, October 11, 2018 6:02 PM -
User475983607 posted
In my asp.net project, there is a multiple line text box to let user input comments.
If user input a comment like below.
Thank you for your fax.
I'll reissue a check to you.
If you have any question, please call me at xxx-xxx-xxxx.
This comment will save as varchar into a SQL server table.
The problem is that once review this comment, three lines text will display like one line text as below.
Thank you for your fax.I'll reissue a check to you.If you have any question, please call me at xxx-xxx-xxxx.
How to fix it?
Browsers do not display white space characters, if the comments are displayed on a web page, you need to replace the newline character (\n\r) to an HTML newline (<br />)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MultilineTextBoxEncode.aspx.cs" Inherits="WebFormsApp.MultilineTextBoxEncode" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox> </div> <div> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> </div> <div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </div> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebFormsApp { public partial class MultilineTextBoxEncode : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = TextBox1.Text.Replace(Environment.NewLine, "<br/>"); } } }
Thursday, October 11, 2018 6:07 PM -
User546194788 posted
The problem is that I don't know where the user hit [Enter] key to input text in another line.
Friday, October 12, 2018 12:14 PM -
User475983607 posted
For the second time, browsers do not display newline charaters (enter). If you want to display newlines on an html page, replace the newline characters with an html line break as shown in the sample code. If you have other formatting needs, then explain clearly what problem you are trying to solve.Friday, October 12, 2018 1:13 PM -
User61956409 posted
Hi aspfun,
If you are using the asp.net TextBox control with multiline mode, your example comment would be saved as below:
Thank you for your fax.\r\n\r\nI'll reissue a check to you.\r\n\r\nIf you have any question, please call me at xxx-xxx-xxxx.
To display comment in multi lines in asp.net Label control, the solution that mgebhard shared should work, you can replace the newline string with html <br/> tag.
The problem is that I don't know where the user hit [Enter] key to input text in another line.If the comment that you retrieved from database still can not be rendered as expected in multi lines, please share us the actual data of comment that you stored in your database, perhaps the data that you stored in database does not contain line break(s).
With Regards,
Fei Han
Tuesday, October 16, 2018 9:49 AM -
User-1171043462 posted
Refer
Save (Insert) and Retrieve (Display) TinyMCE contents from database in ASP.Net
Tuesday, October 16, 2018 1:26 PM