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

Forums / General Discussions / DesignMode, cmspagemode=edit, etc.

DesignMode, cmspagemode=edit, etc.

4 posts, 0 answered
  1. Bob Pinna
    Bob Pinna avatar
    13 posts
    Registered:
    10 Apr 2005
    07 Apr 2009
    Link to this post
    When adding a module custom control to the Sitefinity interface what is the recommended way to:

    1. Detect if the control is being shown on a page via the "View" tab (i.e., the control expects query string arguments at runtime and redirects, want to render dummy data when shown from View).
    2. Detect if the control is being shown on the "edit this page" design surface inside of sitefinity (cmspagemode=edit?).

    Thanks!

  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    10 Apr 2009
    Link to this post
    Hello Bob Pinna,

    In both cases you might use these approaches:
    Telerik.Cms.Web.CmsPageBase page = this.Page as Telerik.Cms.Web.CmsPageBase;  
    if (page.PageMode != Telerik.Cms.Web.CmsPageMode.Edit)  
    {  
        //something 
    }  

    or, you can take the page mode through the query string:
    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;  
        }  

    All the best,
    Georgi
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. Andreas
    Andreas avatar
    49 posts
    Registered:
    29 Dec 2007
    29 Oct 2009
    Link to this post
    For future reference, in the querystring one, the conditions should be >= 0 (or > -1) since the "cmspagemode=edit" is at position 0 when entering edit mode (or preview mode). Was getting some weird results before I noticed it.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Oct 2009
    Link to this post
    Hi Andreas,

    You can also directly use

    HttpContext.Current.Request.QueryString[ "cmspagemode" ] == "edit"

    or checking the mode as shown below:

    string mode = HttpContext.Current.Items["cmspagemode"] as string;
    // SAMPLE CONDITION
    if(mode == "edit" || mode == "preview")
    {
      // DO SOMETHING HERE
    }

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered