I set a value for a Multiline Textbox like this.
textBox1.Text = "Line1rnrnLine2";
But, only one line space in output.
When I read the value of textbox, I read "Line1rnLine2";
Why does ASP.NET not support more then one lineline character?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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>
Method 2
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>
Method 3
Try this one
textBox1.Text = “Line1” + Environment.NewLine + “Line2”;
Working fine for me…
Method 4
I had the same problem. If I add one Environment.Newline I get one new line in the textbox. But if I add two Environment.Newline I get one new line.
In my web app I use a whitespace modul that removes all unnecessary white spaces. If i disable this module I get two new lines in my textbox. Hope that helps.
Method 5
When page IsPostback, the following code work correctly. But when page first loading, there is not multiple newline in the textarea. Bug
textBox1.Text = "Line1rnrnrnLine2";
Method 6
While dragging the TextBox it self Press F4 for Properties and under the Textmode set to Multiline, The representation of multiline to a text box is it can be sizable at 6 sides. And no need to include any newline characters for getting multiline. May be you set it multiline but you dint increased the size of the Textbox at design time.
Method 7
textBox1.Text = "Line1rrLine2";
Solved the problem.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0