Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline TextBox multiple newline

I set a value for a Multiline Textbox like this.

textBox1.Text = "Line1\r\n\r\nLine2"; 

But, only one line space in output.

When I read the value of textbox, I read "Line1\r\nLine2";

Why does ASP.NET not support more then one lineline character?

like image 216
selami Avatar asked May 06 '11 10:05

selami


People also ask

Can you Enter more than one line in TextBox control?

A multiline text box allows you to display more than one line of text in the control. If the WordWrap property is set to true , text entered into the multiline text box is wrapped to the next line in the control.

How do I insert a line break in a text box?

Of course, there are situations in which there is need to add line breaks. You can do so by simply hitting Shift + Return or Shift + Enter , respectively.

How do I make multiple lines in a text box in HTML?

To create a multi-line text input, use the HTML <textarea> tag. You can set the size of a text area using the cols and rows attributes. It is used within a form, to allow users to input text over multiple rows. Specifies that on page load the text area should automatically get focus.


2 Answers

You need to set the textbox to be multiline, this can be done two ways:

In the control:

<asp:TextBox runat="server" ID="MyBox" TextMode="MultiLine" Rows="10" /> 

Code Behind:

MyBox.TextMode = TextBoxMode.MultiLine; MyBox.Rows = 10; 

This will render as a <textarea>

like image 93
Tom Gullen Avatar answered Sep 21 '22 14:09

Tom Gullen


textBox1.Text = "Line1" + Environment.NewLine + "Line2"; 

Also the markup needs to include TextMode="MultiLine" (otherwise it shows text as one line)

<asp:TextBox ID="multitxt" runat="server" TextMode="MultiLine" ></asp:TextBox> 
like image 38
V4Vendetta Avatar answered Sep 18 '22 14:09

V4Vendetta