Prevent control from rendering in edit mode - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Prevent control from rendering in edit mode

  • Prevent control from rendering in edit mode
  • Hi David,

    Controls inheriting from SimpleView have a property IsBackend. If it's true, e.g. in InitializeControls, you could not execute whatever is taking place there. There are other properties as well, like IsDesignMode, that may offer what you need.

  • My controls is a UserControl with code-behind. Is there any documentation on changing this to inherit from SimpleView? 

  • Is there anyway to prevent my ascx control from rendering when in edit mode in the backend? At present it is preventing me from accessing the edit controls of Sitefinity as the CSS is placing some divs over the controls

  • Hello,

    The main difference between custom and user widgets is that custom widgets must inherit the SimpleView class. That makes the registration of custom widgets different, that is, you must provide the complete path when registering a new custom widget in Sitefinity Toolbox. In contrast, you register user widgets by virtual path. In addition, to map the markup file of a custom widget with its code-behind, you must override the LayoutTemplatePath property and put the complete path of the markup instead. For more information, see:

    More information could be found in our Sitefinity documentation.

    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)
             if(this.IsDesignMode() && !this.IsPreviewMode())
                //do something

    Alternatively, you can use SystemManager.IsDesignMode when checking for DesignMode in a control.

    You could check whether your control which inherits from UserControl in in design mode using:

    public partial class WebUserControl2 : System.Web.UI.UserControl
            protected void Page_Load(object sender, EventArgs e)
                if (this.IsDesignMode())
                 //hide it here

    There is no need to revert your control and inherit from SimpleView to be able to check whether the control is in design mode.

    However if you decide you can derive your control from the SimpleView or the SimpleScriptView classes, which are part of the Sitefinity SDK. They are designed to improve the development of controls for Sitefinity. For a detailed step-by-step tutorial on creating controls, see How to create a NewsRotator control.

    Stefani Tacheva
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
  • Hi Stefani Tacheva,

    How can I implement the same functionality in my Mvc widget?
    I don’t want do display the fields in design mode.


  • Hi. In Mvc widgets you can use conditions for determine backend and preview mode like that

    if (!SitefinityContext.IsBackend)
    //if it is not backend
    if (!SitefinityContext.IsPreviewMode)
    //if it is not preview mode


  • Hi Victor,

    Thank you for your reply and my issue got resolved.