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

Forums / Developing with Sitefinity / Prevent control from rendering in edit mode

Prevent control from rendering in edit mode

7 posts, 0 answered
  1. David Rhodes
    David Rhodes avatar
    42 posts
    Registered:
    24 May 2005
    06 Mar 2014
    Link to this post

    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

  2. Arno
    Arno avatar
    249 posts
    Registered:
    08 Sep 2010
    06 Mar 2014 in reply to David Rhodes
    Link to this post

    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.

  3. David Rhodes
    David Rhodes avatar
    42 posts
    Registered:
    24 May 2005
    06 Mar 2014 in reply to Arno
    Link to this post

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

  4. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    Registered:
    21 Nov 2016
    11 Mar 2014
    Link to this post
    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)
    {
             base.OnPreRender(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.

    Regards,
    Stefani Tacheva
    Telerik
    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
  5. Balanjaneyulu
    Balanjaneyulu avatar
    35 posts
    Registered:
    11 Feb 2016
    28 Jun in reply to Stefani Tacheva
    Link to this post

    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.

    Thanks,
    Balu

  6. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    28 Jun in reply to Balanjaneyulu
    Link to this post

    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
    }

     

  7. Balanjaneyulu
    Balanjaneyulu avatar
    35 posts
    Registered:
    11 Feb 2016
    30 Jun in reply to Victor Leontyev
    Link to this post

    Hi Victor,

    Thank you for your reply and my issue got resolved.

    Thanks,
    Balu
7 posts, 0 answered