回车(ASCII字符13)从文本框的值回发时丢失的ASP.NET更新面板中使用 [英] Carriage Return (ASCII chr 13) is missing from textbox postback values when used within an ASP.NET Update panel

查看:206
本文介绍了回车(ASCII字符13)从文本框的值回发时丢失的ASP.NET更新面板中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本模式= TextBoxMode.MultiLine是一个AJAX更新面板中使用的ASP.NET文本框。到.text值一直$ P $对 - 设置为一个值,该值具有多行。

I have an ASP.NET TextBox with TextMode = TextBoxMode.MultiLine that is used within an AJAX Update Panel. The .Text value has been pre-set to a value that has multiple lines.

当使用铬(7.0.517.41)或Firefox(3.6.11)与对照工作贴回服务器,如果用户没有编辑的$ P $对 - 设定值回车是失去了对值。

When using Chrome(7.0.517.41) or Firefox(3.6.11) working with the controls posted back value on the server the carriage return is lost if the user hasn't edited the pre-set value.

例如。 初始。文值设定在页面加载时:

E.g. Initial .Text value set when the page loads:

1号线/ R / nline2 / R / nline3

"line 1/r/nline2/r/nline3"

。文中从Chrome或Firefox回传,用户已经editied的文本框的值:

Value of .Text on postback from Chrome or Firefox where the user has editied the textbox:

1号线/ R / nline2 / R / nline3

"line 1/r/nline2/r/nline3"

。文中从Chrome或Firefox回传,用户还没有editied文本框值:

Value of .Text on postback from Chrome or Firefox where the user has not editied the textbox:

行1 / nline2 / nline3

"line 1/nline2/nline3"

为什么回车丢失,我怎么能解决这个?

Why is the carriage return being lost and how can I resolve this?

推荐答案

我已经找到了克雷格·沃德曼<博客文章一href="http://www.craigwardman.com/blog/index.php/2009/02/textbox-crlf-in-firefox-using-ajax-updatepanel/"相对=nofollow>文本框CRLF在Firefox中使用AJAX的UpdatePanel 的discribes同样的问题。

I've found a blog post by Craig Wardman Textbox CrLf in Firefox using AJAX UpdatePanel that discribes the same problem.

当使用一个多行TextBox的ASP.NET AJAX更新面板里面,你可能会遇到的问题,在使用Firefox(和潜在的其他浏览器)服务器上的文字回车换行。

When using a MultiLine textbox inside an ASP.NET AJAX update panel, you may encounter problems with carriage return line feeds in your text on the server using Firefox (and potentially other browsers).

Internet Explorer使用的Windows风格CRLF(13 10)换行符在文本区域,但Firefox使用的Unix风格的LF(10)只。

Internet Explorer uses the Windows style CrLf (13 10) for newlines in a textarea but Firefox uses Unix style Lf (10) only.

在一个同步回发,似乎ASP.NET修复这一点,你会得到CRLF在服务器上的文字。但是,当你回发异步使用AJAX,你只能得到LF在文本时,Firefox的使用。

On a synchronous postback it seems ASP.NET fixes this and you will get CrLf in your text on the server. However, when you are posting back asynchronously using AJAX, you only get Lf in your text when Firefox is used.

他提出的解决方案是解决问题的服务器端:

His proposed solution is to resolve the issue server side:

public static string CleanUnixCrLf(string textIn)
{
   //firefox only uses Lf and not CrLf
   return System.Text.RegularExpressions.Regex.Replace(textIn, "([^\r])[\n]", "$1\r\n");
}

这将工作,但我有兴趣,可以无需检查每一个调回值解决该问题的解决方案。

This will work, but I'd be interested in a solution that could fix the issue without having to check every posted back value.

修改

该解决方案不处理多个相邻的新生产线。 追加 .Replace(\ñ\ N,\ñ\ r \ N)其他替代是一种选择。

This solution doesn't handle multiple adjacent new lines. Appending .Replace("\n\n", "\n\r\n") to the other replace is one option.

这篇关于回车(ASCII字符13)从文本框的值回发时丢失的ASP.NET更新面板中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆