我有一个设置为多行模式的文本框。其中的文本属性包含了一些换行符(\r\n)。
为什么在完全回发(postback)时返回的数据会与异步回发(async postback)时不同,异步回发时返回的是"\n"而非"\r\n"?
用户代理:IE、Firefox、Edge、Chrome
ASPX:
<asp:UpdatePanel runat="server" ID="up">
<ContentTemplate>
<asp:TextBox runat="server" ID="tbText" TextMode="MultiLine" Height="200px" />
<asp:Label runat="server" ID="lDump" /><br />
<asp:Button runat="server" ID="btnAsync" Text="Async postback" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button runat="server" ID="btnFull" Text="Full postback" />
aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
btnAsync.Click += Dump;
btnFull.Click += Dump;
if (!IsPostBack)
tbText.Text = "Line1\r\nLine2\r\nLine3";
}
private void Dump(object sender, EventArgs e)
{
lDump.Text = tbText.Text.Replace("\r", "[CR]").Replace("\n", "[LF]");
}
输出:
- 异步回发:行1[换行]行2[换行]行3
- 完整回发:行1[回车][换行]行2[回车][换行]行3