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

Forums / Developing with Sitefinity / Usercontrol.Page == null in administration

Usercontrol.Page == null in administration

3 posts, 0 answered
  1. Lucas
    Lucas avatar
    65 posts
    Registered:
    22 Mar 2010
    26 Apr 2010
    Link to this post
    Hi,

    I have a snippet of code that allow my controls to detect whether I am on the live site or in the administration :

    public static bool? PageIsInAdminisitration(Page controlPage)
     {
         var page = this.Page as Telerik.Cms.Web.CmsPageBase;
             return page.PageMode == Telerik.Cms.Web.CmsPageMode.Edit
                 || page.PageMode == Telerik.Cms.Web.CmsPageMode.Admin;
     }

    Unfortunately, it appears that this.Page can be null in some cases (while editing the page). Am I doing something wrong on my side?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    26 Apr 2010
    Link to this post
    Hello Lucas,

    Use the QueryString from the context

    if (!HttpContext.Current.Request.QueryString["cmspagemode"] == "edit")
    {
      // you are not in edit mode.
       
    }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Lucas
    Lucas avatar
    65 posts
    Registered:
    22 Mar 2010
    26 Apr 2010
    Link to this post
    Are there other situations (eg: other than in Edit mode) where the page might be null?

    I'd prefer not relying on the querystring (well, it's not strongly typed and I fear this might lead to issues later), and I was thinking of treating a null page as an equivalent to CmsPageMode.Edit
Register for webinar
3 posts, 0 answered