Carriage Return (ASCII chr 13) is not present in text field postback values ​​when used in the ASP.NET update pane

I have an ASP.NET text field with TextMode = TextBoxMode.MultiLine, which is used in the AJAX update panel. The .Text value was previously set to a value that has multiple lines.

When using Chrome (7.0.517.41) or Firefox (3.6.11) working with controls that are returned to the server, the carriage return is lost if the user has not edited the preset value.

eg. The initial .Text value set when the page loads:

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

.Text value for postback from Chrome or Firefox, where the user edited the text box:

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

.Text value for postback from Chrome or Firefox, where the user did not edit the text field:

"line 1 / nline2 / nline3"

Why is carriage return lost and how can I solve this?

+3
source share
1 answer

I found a blog post from Craig Wardman CrLf Text Box in Firefox using the AJAX UpdatePanel that describes the same issue.

When using the MultiLine text box inside the ASP.NET AJAX update panel, you may run into problems with carriage return channels in the text on the server using Firefox (and possibly other browsers).

Internet Explorer CrLf Windows (13 10) , Firefox Unix Lf (10).

ASP.NET , CrLf . , AJAX, Lf , Firefox.

, :

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");
}

, , , .

Edit

. .Replace("\n\n", "\n\r\n") - .

+5

Source: https://habr.com/ru/post/1771400/


All Articles