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

Forums / Developing with Sitefinity / How to Detect Design View

How to Detect Design View

8 posts, 0 answered
  1. Zhi
    Zhi avatar
    10 posts
    Registered:
    27 Sep 2010
    23 Jun 2011
    Link to this post
    Hi there,

    I would like to prevent my custom control from rendering in Sitefinity when in design view and show a message similar to "Cannot view in design view".  This is similar to the way the login control won't render in design view (editing a page in Sitefinity).

    How can I detect if a page is being served up in design view?

    Thanks
    Zhi
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    19 Sep 2016
    23 Jun 2011
    Link to this post
    Hello Zhi,

    You can easily achieve this  using our ControlExtensions:

    IsDesignMode - static method which determines whether the control is in Sitefinity design mode - you  are editing a page. There are also  IsPreviewMode- determines whether the control is in Sitefinity preview mode.
    IsBackend -determines whether a control instance is in backend.  Please refer to the sample code below:

    protected override void OnPreRender(EventArgs e)
    {
             base.OnPreRender(e);         
             if(this.IsDesignMode() && !this.IsPreviewMode())
             {
                 this.Controls.Clear();
     
             }
            
       }
    If you have any additional questions, please let us know.



    Best wishes,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Olivier
    Olivier avatar
    57 posts
    Registered:
    09 Jul 2010
    16 Aug 2011
    Link to this post
    Hi,

    In which namespace is that ?

    All I've found was

    SystemManager.IsDesignMode
    and
    SystemManager.IsPreviewMode

    from Telerik.Sitefinity.Services

    Thank you,

    Olivier
  4. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    19 Sep 2016
    17 Aug 2011
    Link to this post
    Hi Olivier,

    IsDesignMode is a property of the Page control, and is located in the System.Web.UI.ControlExtensions  namespace. It should be available without resolving any references when you use it as this.IsDesignMode from the page's codebehind.

    Kind regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Olivier
    Olivier avatar
    57 posts
    Registered:
    09 Jul 2010
    17 Aug 2011
    Link to this post
    Thanks,

    I was in a Widget/UserControl context, not in a Page, that's why I could not get the method.

    Then I suppose I have to use the SystemManager, from a Widget/UserControl point of view, to know if it's in edition ?

    Olivier
  6. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    19 Sep 2016
    17 Aug 2011
    Link to this post
    Hi Olivier,

    Thank you for the clarification. Yes, when checking for DesignMode in a control, you should use SystemManager.IsDesignMode

    Greetings,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Mark
    Mark avatar
    12 posts
    Registered:
    04 Aug 2010
    17 Aug 2012
    Link to this post
    What if you are in a MasterPage based template. Is there a way of detecting IsDesignMode or IsPreviewMode there?
  8. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    19 Sep 2016
    22 Aug 2012
    Link to this post
    Hello Mark,

    Yes, you could use Telerik.Sitefinity.Services.SystemManager  and say something like:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity.Services;
     
    namespace SitefinityWebApp.App_Master
    {
        public partial class Site1 : System.Web.UI.MasterPage
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (SystemManager.IsDesignMode)
                {
      
                }
            }
        }
    }


    All the best,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
8 posts, 0 answered