CraigWardman.com

[ Textbox CrLf in Firefox using AJAX UpdatePanel ]

/Blog/Post

A catalogue of my discoveries in software development and related subjects, that I think might be of use or interest to everyone else, or to me when I forget what I did!

Textbox CrLf in Firefox using AJAX UpdatePanel

Tuesday, 17 February 2009


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 uses the Windows style CrLf (13 10) for newlines in a textarea but Firefox uses Unix style Lf (10) only.

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.

In order to clean this up and have consistant data, I wrote a simple regex replace to make sure all Lf are preceded by a Cr.


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

Labels: ,

Share This!



1 Comments:

Blogger Morgan said...

Hello,

Just noticed this a week ago... Ajax layer is still perfectible...

Bye and continue the good job.

Bye

Morgan (French Asp.Net Dev)

18 Feb 2010 11:17:00  

Post a Comment

<< Home

CraigWardman.com