Multiline TextBox multiple newline

2019-01-14 06:41发布

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?

7条回答
对你真心纯属浪费
2楼-- · 2019-01-14 06:42
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>
查看更多
神经病院院长
3楼-- · 2019-01-14 06:43

textBox1.Text = "Line1\r\r\Line2";
Solved the problem.

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-14 06:45

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.

查看更多
我命由我不由天
5楼-- · 2019-01-14 06:53

Try this one

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

Working fine for me...

查看更多
▲ chillily
6楼-- · 2019-01-14 07:05

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.

查看更多
不美不萌又怎样
7楼-- · 2019-01-14 07:06

When page IsPostback, the following code work correctly. But when page first loading, there is not multiple newline in the textarea. Bug

textBox1.Text = "Line1\r\n\r\n\r\nLine2";
查看更多
登录 后发表回答