How to Detect Design View

Posted by Community Admin on 04-Aug-2018 05:53

How to Detect Design View

All Replies

Posted by Community Admin on 23-Jun-2011 00:00

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

Posted by Community Admin on 23-Jun-2011 00:00

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

Posted by Community Admin on 16-Aug-2011 00:00

Hi,

In which namespace is that ?

All I've found was

SystemManager.IsDesignMode
and
SystemManager.IsPreviewMode

from Telerik.Sitefinity.Services

Thank you,

Olivier

Posted by Community Admin on 17-Aug-2011 00:00

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

Posted by Community Admin on 17-Aug-2011 00:00

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

Posted by Community Admin on 17-Aug-2011 00:00

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

Posted by Community Admin on 17-Aug-2012 00:00

What if you are in a MasterPage based template. Is there a way of detecting IsDesignMode or IsPreviewMode there?

Posted by Community Admin on 22-Aug-2012 00:00

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

This thread is closed