1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How do I know what mode the page is in?

How do I know what mode the page is in?

5 posts, 0 answered
  1. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    23 Feb 2009
    Link to this post
    If you're working with an extended ContentView control, how do you know what mode the page is in?  

    this.BehaviorMode doesn't tell me anything useful.  If it's in Auto, all it ever returns is BehaviorMode.Auto.  If I set it to Detail in the properties, then it never returns anything other than that. 



  2. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    23 Feb 2009
    Link to this post
    Hello Mike,

    The BehaviorMode property of ContentView has nothing to do with the page mode. It can only get or set the mode of the ContentView control - Master of Detail. Master usually displays a list of items, while Details displays a single item. Setting the property to Auto means that the control itself would decide what mode to display in (e.g. clicking an item in the list would switch to detail automatically).

    If you want the mode the page is in (edit, preview), then you can get it from the querystring. Notice how the URL changes once you click the Edit button for a page. So I'm not really sure which one of these you want. If you want some other mode, then please elaborate.

    Kind regards,
    Slavo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    23 Feb 2009
    Link to this post
    Yes, that's what I want.  The Behavior Mode of the ContentView.  I'm trying to set the properties of certain controls that exist only in the details mode (SingleItemView).   It seems to me there was a way to tell whether you're looking at the list view or the single item view.  I know there's something internally that handles it, because it knows which template to pick.

    I can figure out whether a page is in Edit or Preview mode by looking at the raw URL; even when the displayed URL is something different, the raw URL contains the cmspagemode query string.

    But I want to know whether the ContentView control is displaying a list, or the single detail item.

    Regards,
    Mike Sharp
  4. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    23 Feb 2009
    Link to this post
    Hi Mike,

    The ContentView control uses the BehaviorMode property to determine which mode to display in, but does not set it once this is determined. So if the value is Detail, the control is always displaying item details, if the value is Master, the control always displays a list of items. Auto doesn't tell you anything and it could be both, so you have to try that too. This is a simplified version of the logic inside of the control and I guess you would have to use something similar:

    if (BehaviorMode == BehaviorModes.Auto || behaviorMode == BehaviorModes.Detail) 
        if (Context.Items.Contains(Manager.Provider.ContentItemKey)) 
            itemId = (Guid)((IUrlRewriteData)Context.Items[Manager.Provider.ContentItemKey]).Data; 
        else if (!String.IsNullOrEmpty(Context.Request[ContentItemKey])) 
            itemId = new Guid(Context.Request[ContentItemKey]); 
     
    if (itemId != Guid.Empty) 
        // filter item by ID - only show one. Skipped for brevity 
        behaviorModeImpl = BehaviorModes.Detail; 
        CreateSingleContent(); 
    else if(behaviorMode == BehaviorModes.Auto || behaviorMode == BehaviorModes.Master) 
        behaviorModeImpl = BehaviorModes.Master; 
        CreateContentList(); 

    Note that behaviorModeImpl actually contains the current mode, but it is not available to you as a public property. So you would have to imitate this logic and check whether the controls you need to manipulate actually exist every time.

    All the best,
    Slavo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    23 Feb 2009
    Link to this post
    Ah, thank you.  that's exactly what I was looking for.  I should have figured this out for myself, I guess, as I'm already using the UrlRewriteData to get the ID of the content item:

    object obj = this.Context.Items["CntItem"];  
    if (obj != null)  
    {  
        hubId = (Guid)((UrlRewriteData)obj).Data;  
    }  
     

    I guess I need more sleep!  ;^)

    Your appoach looks more robust, so I think I'll use that instead.

    Thanks!
    Mike Sharp
Register for webinar
5 posts, 0 answered