How to Detect Design View - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

How to Detect Design View

  • How to Detect Design View
  • 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
  • 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
  • Hi,

    In which namespace is that ?

    All I've found was

    SystemManager.IsDesignMode
    and
    SystemManager.IsPreviewMode

    from Telerik.Sitefinity.Services

    Thank you,

    Olivier
  • 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
  • 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
  • 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
  • What if you are in a MasterPage based template. Is there a way of detecting IsDesignMode or IsPreviewMode there?
  • 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