Sitecore Save Dialog appears for unchanged content

Have you ever experienced that Sitecore keeps popping the “Do you want to save the changes to the item?” dialog box, even when you have made no changes to the item? And the box keeps appearing, even when you have chosen “yes”?

Save Dialog

Save Dialog

This scenario can occur if the contents of any multiline field or textbox field contains new lines \n or carriage returns \r.

Memo Box with \r or \n

Memo Box with \r or \n

In rare situations, the browser will interprete \n and \r differently from Sitecore, thus telling Sitecore that the contents in the box differs from the contents in the Sitecore database.

The situation rarely occurs with manually entered text, but if you have programatically added the text to the box, the \n and \r might misalign.

So if you add text to the multiline field (or textbox field) you should ensure that any \n and \r are removed before adding the text.

I made this string extension method to remove all new lines, carriage returns, tabs and strange \xA0’s (which looks like a space but isn’t):

public static string CleanNewLinesTabsAndOtherStuff(this string s)
  return s.Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " ").Replace("\t", " ").Replace('\xA0', '\x20');

I replace all of them with spaces, but in other situations you could replace them with string.Empty.

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in c#, Sitecore 6 and tagged , , , , , . Bookmark the permalink.

4 Responses to Sitecore Save Dialog appears for unchanged content

  1. Nick Allen says:

    Awesome, I have been wondering what causes this for a very long time!


  2. Pingback: Seek and Destroy: Root Out Newlines and Carriage Returns in Multi-Line Text Fields «

  3. flaviotsf says:

    Cool investigation! It would be better if the logic under the “Save” was fixed instead. Unsure if sitecore is working / has worked on this issue.
    Do you have a pipeline action on the ‘Save’ to fix all the MultiLine fields?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.