【发布时间】:2015-02-16 21:10:20
【问题描述】:
我有一个 txt 文件,我尝试使用 asp:label 在 aspx 页面上显示该文件。
我希望标签尊重 .txt 文件的结构,但文本显示在一个大包装中,尽管页面源表明它已正确加载。
另一种方法是使用多行文本框,但这让我“感觉”好像我错过了一些简单的标签。
如何让标签尊重 .txt 中的换行符?
.cs:
StreamReader sr = new StreamReader(Server.MapPath(@"~/ReleaseNotes.txt"));
lblReleaseNotes.Text = sr.ReadToEnd();
StreamReader sr1 = new StreamReader(Server.MapPath(@"~/ReleaseNotes.txt"));
txtReleaseNotes.Text = sr1.ReadToEnd();
.apsx:
<asp:Label ID="lblReleaseNotes" runat="server" Text="[unable to read ReleaseNotes]" Width="100%" Style="word-wrap: normal; word-break: break-all;" ></asp:Label>
<asp:TextBox ID="txtReleaseNotes" runat="server" Text="[unable to read ReleaseNotes]" ReadOnly="True" TextMode="MultiLine" Width="100%" Height="600" BorderStyle="None" BorderWidth="0"></asp:TextBox>
查看源代码:
<span id="MainContent_lblReleaseNotes" style="display:inline-block;width:100%;word-wrap: normal; word-break: break-all;">SnowKing Release Notes
0.3 - 13/02/2015 - Add Live Google Maps and Run Catalogue
- Generate Release Notes .txt
- Added single column runs catalogue to Fernie page.
- Added page for Val Thorens.
- Added page for Les Meniures.
...(etc)
</span>
【问题讨论】: