Html 多行文本框多个换行符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5909864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 08:28:21  来源:igfitidea点击:

Multiline TextBox multiple newline

asp.nethtmltextboxmultiline

提问by selami

I set a value for a Multiline Textboxlike this.

我为这样的 a 设置了一个值Multiline Textbox

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";

当我读取文本框的值时,我读到"Line1\r\nLine2";

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

为什么 ASP.NET 不支持多于一个 lineline 字符?

采纳答案by TimW

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.

我有同样的问题。如果我添加一个 Environment.Newline,我会在文本框中获得一个新行。但是如果我添加两个 Environment.Newline 我会得到一个新行。在我的网络应用程序中,我使用了一个空格模块来删除所有不必要的空格。如果我禁用此模块,我的文本框中会出现两行新行。希望有帮助。

回答by Tom Gullen

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>

这将呈现为 <textarea>

回答by V4Vendetta

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

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

此外,标记需要包括 TextMode="MultiLine" (否则它将文本显示为一行)

<asp:TextBox ID="multitxt" runat="server" TextMode="MultiLine" ></asp:TextBox>

回答by Harpal

Try this one

试试这个

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

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

Working fine for me...

对我来说工作正常...

回答by aliye

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

当页面 IsPostback 时,以下代码正常工作。但是当页面第一次加载时,textarea中没有多个换行符。漏洞

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

回答by Sai Kalyan Kumar Akshinthala

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 newlinecharacters for getting multiline. May be you set it multiline but you dint increased the size of the Textbox at design time.

拖动TextBox本身时按F4属性并在Textmode设置为Multiline下,多行到文本框的表示是它可以在6边上调整大小。并且不需要包含任何换行符来获取多行。可能是您将其设置为多行,但您在设计时却没有增加文本框的大小。

回答by selami

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

textBox1.Text = "Line1\r\r\Line2";
解决了问题。