Environment.NewLine不在一个文本框中工作

时间:2018-03-20 12:17:01

标签: c# asp.net .net vb.net

请原谅我,如果有答案,我找不到符合这种情况的那个。

我在Code Behind中使用VB.Net创建了一个ASP.Net Web Forms站点。

有一个页面可以从SQL DB加载数据。除了一个文本框外,一切正常。我得到了所有数据,但它没有像其他文本框那样格式化。

以下是IS工作的代码:

ASP.Net Textbox - Root Cause
<asp:TextBox ID="txbRootCause" runat="server" CssClass="text-primary" TextMode="MultiLine" Rows="3" Width="400px" />

VB.Net Code Behind
Case "rc"
    For i As Integer = 0 To sqlDT.Rows.Count - 1
        sectionString = sectionString & sqlDT.Rows(i)("entrydatetime") & " " & sqlDT.Rows(i)("submittedby") & " " & sqlDT.Rows(i)("rootcause") &  Environment.NewLine
    Next
    txbRootCause.Text = sectionString

String that is built
"3/19/2018 14:37:00 Z.German Admin Root Cause" & vbCrLf & "3/19/2018 14:54:00 L.Ludwig Adding root cause because Zach said so." & vbCrLf

它构建一个文本字符串并将其分配给文本框。请注意,该字符串末尾有一个Environment.NewLine,以便每个条目都在一个新行开始。它在其他五个文本框中工作正常。 (文本框上的名称不同)

现在这是无效的代码

ASP.Net Textbox - Reviewed
<asp:TextBox ID="txbReviews" runat="server" CssClass="text-primary" TextMode="MultiLine" Rows="3" Width="400px" />

VB.Net Code Behind
Case "rv"
    For i As Integer = 0 To sqlDT.Rows.Count - 1
        sectionString = sectionString & sqlDT.Rows(i)("entrydatetime") & " " & sqlDT.Rows(i)("submittedby") & " " & sqlDT.Rows(i)("reviewed") & Environment.NewLine
    Next
    txbReviews.Text = sectionString

String that is built
"3/19/2018 14:37:00 Z.German Admin Review Example" & vbCrLf & "3/19/2018 L.Ludwig Reviewing :-) " & vbCrLf

它使用新行构建完全相同类型的文本字符串,但是当它显示时,新行不会放入代码中。

这是两个文本框的图像。

enter image description here

注意两行不同的文字。现在这是一个不起作用的那个:

enter image description here

请注意,新行在评论框中不起作用。我错过了什么?我似乎找不到合理的原因。

有人知道我可能搞砸了吗?

1 个答案:

答案 0 :(得分:1)

这不是服务器端问题,而是Internet Explorer问题。 Internet Explorer以不同方式处理white-space。我打赌你有white-space: normal;

Normal

您可以尝试不同的选项,但white-space: pre-line;可以胜任:

preline

相关问题