More in this section

Forums / Developing with Sitefinity / Editing and Publishing a Page in a Single Round-trip

Editing and Publishing a Page in a Single Round-trip

3 posts, 1 answered
  1. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    23 Sep 2009
    Link to this post
    I can't seem to edit a page and publish it without making two posts to the server. If I try to do it all at once, the page is locked. If I split the same code up into two pieces, posted on two separate round-trips, it works just fine.

    Here's the code. Note the comments within.

    First, the all-in-one code:

            protected void btnItsLocked_Click(object sender, EventArgs e) 
            { 
                Guid PageID = new Guid(txtTitle.Text); 
                CmsManager m_Manager = new CmsManager(); 
     
                ICmsPage ThePage = (ICmsPage)m_Manager.GetPage(PageID, true); 
     
                // The Staged Page claims it is neither checked out  
                // or locked after .CheckOut() is called. 
                if (!ThePage.Staged.IsCheckedOut) 
                    ThePage.Staged.CheckOut(); 
     
                ThePage = (ICmsPage)m_Manager.GetPage(PageID, true); 
                ThePage.Staged.AddControl("Content"new LiteralControl("<p>Sample page content</p>")); 
     
                m_Manager.SavePage(ThePage); 
     
                ThePage = (ICmsPage)m_Manager.GetPage(PageID, true); 
                ThePage.Staged.CheckIn(); 
     
                ThePage = (ICmsPage)m_Manager.GetPage(PageID, true); 
                ThePage.Publish(); 
     
                // Staged still claims it is unlocked and checked out 
            } 
     


    Now the same code in two stages:

    Stage 1:
            protected void btnEdit_Click(object sender, EventArgs e) 
            { 
                Guid PageID = new Guid(txtTitle.Text); 
                CmsManager m_Manager = new CmsManager(); 
     
                ICmsPage ThePage = (ICmsPage)m_Manager.GetPage(PageID, true); 
     
                if (!ThePage.Staged.IsCheckedOut) 
                    ThePage.Staged.CheckOut(); 
     
                ThePage = (ICmsPage)m_Manager.GetPage(PageID, true); 
                ThePage.Staged.AddControl("Content"new LiteralControl("<p>Sample page content</p>")); 
     
                m_Manager.SavePage(ThePage); 
                // Staged still claims it is unlocked and checked out 
            } 
     

    Stage 2:
            protected void btnPublishOnly_Click(object sender, EventArgs e) 
            { 
                Guid PageID = new Guid(txtTitle.Text); 
                CmsManager m_Manager = new CmsManager(); 
     
                // Now staged claims it is checked out and locked 
                // before .CheckIn() is called 
                ICmsPage ThePage = (ICmsPage)m_Manager.GetPage(PageID, true); 
                ThePage.Staged.CheckIn(); 
     
                ThePage = (ICmsPage)m_Manager.GetPage(PageID, true); 
                ThePage.Publish(); 
            } 
     


    Am I missing a step in the first example commit the transaction after the check out and start a new transaction before the save and publish? I just don't know what I'm doing wrong.

    Thanks,
    Jeff
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    23 Sep 2009
    Link to this post
    Hi Jeff,

    You could try using the code below:

    CmsManager pageManager = new CmsManager(); 
    Guid pageID = new Guid("F9B2B538-2AF2-428A-AD4F-A374C0A92F2A"); 
    ICmsPage cmsPage = (ICmsPage)pageManager.GetPage(pageID, true); 
    cmsPage.Staged.AddControl("Content"new LiteralControl("HELLO WORLD")); 
    pageManager.SavePage(cmsPage); 
    cmsPage.Publish(); 
     

    I hope this helps.

    All the best,
    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.
    Answered
  3. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    23 Sep 2009
    Link to this post
    Hi Ivan,

    So essentially skip the check out/check in and just save and publish. That works!

    From now on, I will only check out when I need to keep the page locked longer than a single postback.

    Thanks.

    Jeff
Register for webinar
3 posts, 1 answered