多行文本框多个换行符

发布于 2024-11-06 02:51:09 字数 228 浏览 9 评论 0原文

我为 Multiline Textbox 设置了一个值,如下所示。

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

但是,输出中只有一行空间。

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

撩发小公举 2024-11-13 02:51:09

您需要将文本框设置为多行,可以通过两种方式完成:

在控件中:

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

代码隐藏:

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

这将呈现为

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>

猫九 2024-11-13 02:51:09
textBox1.Text = "Line1" + Environment.NewLine + "Line2";

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

<asp:TextBox ID="multitxt" runat="server" TextMode="MultiLine" ></asp:TextBox>
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>
美男兮 2024-11-13 02:51:09

试试这个

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

对我来说工作得很好...

Try this one

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

Working fine for me...

洛阳烟雨空心柳 2024-11-13 02:51:09

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

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.

救赎№ 2024-11-13 02:51:09

当页面IsPostback时,以下代码可以正常工作。但是,当页面首次加载时,文本区域中没有多个换行符。漏洞

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

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";
誰認得朕 2024-11-13 02:51:09

拖动文本框本身时,按F4键设置属性,并将文本模式设置为多行,多行在文本框中的表示是它可以在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.

梦言归人 2024-11-13 02:51:09

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文