More in this section

Forums / Developing with Sitefinity / Determine Page Mode

Determine Page Mode

4 posts, 0 answered
  1. Allen
    Allen avatar
    71 posts
    Registered:
    04 Aug 2007
    21 Mar 2008
    Link to this post
    Is there a way to programatically determine if the page is in "design" mode?  And by this I don't mean that the designer has clicked "edit".  Instead, I mean simply that the page is being viewed from the admin side and not the public side.

    Thanks
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    21 Mar 2008
    Link to this post
    Hello Allen,

    Yes, it is possible.
    I'm attaching a custom user control that makes this check for you and I am also posting the code so that other forum readers can refer to it.

       protected void Page_Load(object sender, EventArgs e) 
        { 
           //perform the check. 
           //returns true if it is viewed in administration part. 
           IsPageInAdmin(); 
        } 
        private bool IsPageInAdmin() 
        { 
           // will return TRUE is the page is viewed in administration part 
          if (this.Page.Request.QueryString.ToString().IndexOf("preview") > 0) 
              return true
          // will return TRUE is the page is in editing mode 
          if (this.Page.Request.QueryString.ToString().IndexOf("edit") > 0) 
              return true
          // the page is viewed in the public part. 
          return false
        } 

    To use this control, simply upload it to the Sitefinity controls toolbox, and drop it on the pages that you want to check.
    I hope you find this helpful.

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Allen
    Allen avatar
    71 posts
    Registered:
    04 Aug 2007
    21 Mar 2008
    Link to this post
    Awesome!  Thanks!
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    21 Mar 2008
    Link to this post
    Hi Allen,

    Ooops, this is just a quick follow up.
    It should be :
        protected void Page_Load(object sender, EventArgs e) 
        { 
           //perform the check. 
           //returns true if it is viewed in administration part. 
           IsPageInAdmin(); 
        } 
        private bool IsPageInAdmin() 
        { 
           // will return TRUE is the page is viewed in administration part 
            if (this.Page.Request.QueryString.ToString().IndexOf("cmspagemode=preview") > 0) 
              return true
          // will return TRUE is the page is in editing mode 
            if (this.Page.Request.QueryString.ToString().IndexOf("cmspagemode=edit") > 0) 
              return true
          // the page is viewed in the public part. 
          return false
        } 

    I have attached the modified control :)

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
4 posts, 0 answered