ASPX templates
Version 5.x > ASPX templates > Detect if Page is Being Loaded in CMSDesk View modes: 
User avatar
Member
Member
eric.rovtar - 1/28/2011 1:09:38 PM
   
Detect if Page is Being Loaded in CMSDesk
Hi!

I want to redirect a page template to include a query string and make it bookmarkable, but when I have this code in my PageLoad method:
string redirect = Request.QueryString["aliasPath"] + "?campus=" + CurrentCampus;
if ((currentHash.Value != null) && (currentHash.Value != ""))
{
redirect = redirect + "#" + currentHash.Value.Replace("#", "");
}

Response.Redirect(redirect);


It causes the EditableRegions to load as rendered in the CMSDesk, and I can't edit them.

Is there a way to detect when the page is loading within the CMSDesk and then not call the Redirect command?

Thanks!

User avatar
Kentico Support
Kentico Support
kentico_radekm - 2/1/2011 2:32:46 AM
   
RE:Detect if Page is Being Loaded in CMSDesk
Hello.

Well, if I understand you well, I guess the best way to determine this is to compare current ViewMode with one from the ViewModeEnum enumeration (as listed below),

e.g. by using CMSContext.ViewMode property, like:

if (CMSContext.ViewMode == ViewModeEnum.LiveSite)
{
// perform only when in the live site mode
}


and vice-versa with NOT operator (when not in live site).

The enumeration also contains various modes that can be distinguished:

namespace CMS.PortalEngine
{
// Summary:
// Page mode enumeration
public enum ViewModeEnum
{
// Summary:
// Live site mode
LiveSite = 0,
//
// Summary:
// Preview mode
Preview = 2,
//
// Summary:
// Edit mode - content editing
Edit = 3,
//
// Summary:
// Edit mode - content editing (editing disabled)
EditDisabled = 4,
//
// Summary:
// Edit mode - not current page
EditNotCurrent = 5,
//
// Summary:
// Edit mode with disabled controls - when not authorized or cannot edit
Design = 6,
//
// Summary:
// Design mode with disabled controls - for portal engine pages
DesignDisabled = 7,
//
// Summary:
// Edit form mode - for portal engine pages
EditForm = 8,
//
// Summary:
// Unknown / does not matter
Unknown = 9,
//
// Summary:
// Properties tab
Properties = 10,
//
// Summary:
// Product tab
Product = 11,
//
// Summary:
// User widgets mode
UserWidgets = 12,
//
// Summary:
// User widgets mode with disabled functionality (for preview mode)
UserWidgetsDisabled = 13,
//
// Summary:
// Group widgets mode
GroupWidgets = 14,
}
}


Best Regards,
Radek Macalik