Prevent control from rendering in edit mode
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
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?
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:
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
SystemManager.IsDesignMode
when checking for DesignMode in a control.public
partial
class
WebUserControl2 : System.Web.UI.UserControl
protected
void
Page_Load(
object
sender, EventArgs e)
if
(
this
.IsDesignMode())
//hide it here
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
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.
Thanks,
Balu