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

Forums / Developing with Sitefinity / You cannot change a value of an object that is not in transaction.

You cannot change a value of an object that is not in transaction.

2 posts, 1 answered
  1. Sachin
    Sachin avatar
    18 posts
    Registered:
    10 Nov 2010
    25 Apr 2011
    Link to this post
    Hi,

    I am trying to change the "Show in Navigation" property of one of the section of website programmatically but I am getting this error:

    You cannot change a value of an object that is not in transaction.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Nolics.ORMapper.Base.NolnetException: You cannot change a value of an object that is not in transaction.

    Source Error:

    Line 33:         {
    Line 34: ICmsPage agentPage = (ICmsPage) Manager.GetPage(agentNode.PageID);
    Line 35: agentPage.Navigable = true;
    Line 36: Manager.SavePage(agentPage);
    Line 37: }

    Here is my code.

    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Telerik.Web.UI;
    using Telerik.Cms;
    using Telerik.Cms.Web;

    public partial class userControls_sitemap : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SiteMapRadTreeView.DataSource = new SiteMapDataSource();
            SiteMapRadTreeView.DataBind();
            SiteMapRadTreeView.ExpandAllNodes();

            showAllAgentsInSitemap();
        }
        public void showAllAgentsInSitemap()
        {
            CmsManager Manager = new CmsManager();
            CmsSiteMapNode parentNode = (CmsSiteMapNode) SiteMap.Provider.FindSiteMapNode("~/MovingCompanies.aspx");        
            IList allAgents = parentNode.ChildNodes;
            foreach (CmsSiteMapNode agentNode in allAgents)
            {
                ICmsPage agentPage = (ICmsPage) Manager.GetPage(agentNode.PageID);             
                agentPage.Navigable = true;
                Manager.SavePage(agentPage);
            }
        }
    }

    What is going wrong here? I checked other threads having similar issue but it didn't help. I am using Sitefinity 3.7.2022.2. Thanks.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Apr 2011
    Link to this post
    Hello Sachin,

    Set the second parameter of GetPage - to true. This will put the page into a transaction.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Answered
2 posts, 1 answered