PageTree listing with startpage results in StackOverflowException

Vote:
 

Hi. I'm new with EPiServer and I'm trying to do a PageTree that shall show all pages down from the startpage including the startpage itself. I have tried to do like this so far.

Codebehind:

 

menuPageTree.PageLink = PageReference.StartPage;
//menuPageTree.PageLoader.GetChildrenCallback = new HierarchicalPageLoader.GetChildrenMethod(LoadChildren);
menuPageTree.DataBind();

 

menuPageTree.PageLink = PageReference.StartPage;
menuPageTree.PageLoader.GetChildrenCallback = new HierarchicalPageLoader.GetChildrenMethod(LoadChildren);
menuPageTree.DataBind();

And the LoadChildren-method looks like this:

 

private PageDataCollection LoadChildren(PageReference pageLink)
{

PageDataCollection pages = DataFactory.Instance.GetChildren(pageLink);

pages.Insert(0, DataFactory.Instance.GetPage(pageLink));

return pages;

 }

The error that I get is a StackOverflowException and it asks me if I have an infinity loop but I can't find one. If I remove the line which inserts the pageLink-page at the first place, the code works but I don't get my startpage as the first item.

I'm I doing it wrong? If so; Any ideas how to make it right?

Regards,
Adam Solander

 

#36989
Feb 16, 2010 14:30
Vote:
 

The pages.Insert(0, DataFactory.Instance.GetPage(pageLink)); will create a infnite loop.

Have you set ShowRootPage=true?

#36991
Feb 16, 2010 15:08
Vote:
 

I hadn't found that one. But now when I tried it I didn't get the result I wanted. I wanted the startpage on the same "level" as its children but not the same as its grandchildren.

This structure should result in this code:

Structure:

Start
 - News
 - About
 - Examples
   -Test

Code:

<ul>
<li>Start</li>
<li>News</li>
<li>About</li>
<li>Examples</li>
<ul>
<li>test</li>
</ul>
</ul>

And the only way i found so to do what I tried to do. Why does the pages.Insert trigger that function again? :/

#36994
Edited, Feb 16, 2010 15:52
Vote:
 

Take a look at MainMenu.ascx.cs in the PublicTemplates project (/Templates/Public/Units/Static/MainMenu.ascx.cs).

protected override void OnLoad(System.EventArgs e)
{
    base.OnLoad(e);

    Menu.PageLink = PageReference.StartPage;
    Menu.PageLoader.GetChildrenCallback = new HierarchicalPageLoader.GetChildrenMethod(LoadChildren);
    Menu.DataBind();
}

/// 
/// Creates the collection for the main menu, adding the startpage
/// 
private PageDataCollection LoadChildren(PageReference pageLink)
{
    PageDataCollection pages = DataFactory.Instance.GetChildren(pageLink);
    pages.Insert(0, DataFactory.Instance.GetPage(pageLink));
    return pages;
}
#37010
Feb 16, 2010 22:48
Vote:
 

My code is based on that code, but the "pages.Insert() causes an infinite loop and I can't understand why.

#37015
Feb 17, 2010 8:24
Vote:
 

Ops sorry, was a bit fast posting that :). What happens if you use all the code in MainMenu.ascx (just use that user control instead of your own), do you get the same error?

#37022
Feb 17, 2010 11:33
Vote:
 

It works perfectly with the Menu-control that is in the MainMenu.ascx as default. No error.

#37028
Feb 17, 2010 13:02
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.