Experience Manager Extension for detecting editing mode serverside
For more info, read the following post: http://albertromkes.com/2013/11/22/how-to-detect-if-you-are-in-the-editor-view-in-xpm-serverside/
Install this extension by following the steps as outlined in this post: http://www.sdltridionworld.com/community/2011_extensions/example_ui.aspx (Paragraph 'Installation')