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

Forums / General Discussions / delete a page and its children

delete a page and its children

2 posts, 0 answered
  1. Phil
    Phil avatar
    89 posts
    Registered:
    19 Oct 2010
    20 Jan 2011
    Link to this post
    I need to delete a page and all its children.  Right now I am not able to delete a pagenode.

    With this code:

            var manager = PageManager.GetManager();
            var guidCourseToDelete = new Guid(ddlCourses.SelectedValue);
            var pn = new PageNode("LessonBuilder1030/", guidCourseToDelete);
    // at this point pn.Id is the correct value
            manager.Delete(pn);

    I get the following error.  Please advise.  Thanks

    [InvalidOperationException: The instance is transient]
       DynamicModule.ns.Wrapped_OpenAccessPageProvider_dafc00828d0746a3be537e06dd250766.Delete(PageNode item) +249
       Telerik.Sitefinity.Modules.Pages.PageManager.Delete(PageNode item) +181
       LessonBuilder_UserControls_DeleteCourse.CmdDeleteCourse_Click(Object sender, EventArgs e) in c:\CurrentFiles\Projects\LessonBuilder1098\LessonBuilderApp\Sitefinity\LessonBuilder\UserControls\DeleteCourse.ascx.cs:39
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBefo
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    21 Jan 2011
    Link to this post
    Hello Phil,

    I am a little bit unsure that the approach you are taking has correct logic. You are first creating a new node and then trying to delete it right away. If you do not want to store the page node you should just not call save changes (this will rollback transaction). In case that you wish to delete a page it is recommended that you use the Fluent API to get the corresponding page node you wish to delete and delete it:
    public void DeletePage(string pageTitle)
    {
        App.WorkWith().Pages()
           .Where(p => p.Page.Title == pageTitle)
           .Delete()
           .SaveChanges();
    }


    Best wishes,
    Radoslav Georgiev
    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
2 posts, 0 answered