The pages.Insert(0, DataFactory.Instance.GetPage(pageLink)); will create a infnite loop.
Have you set ShowRootPage=true?
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? :/
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; }
My code is based on that code, but the "pages.Insert() causes an infinite loop and I can't understand why.
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?
It works perfectly with the Menu-control that is in the MainMenu.ascx as default. No error.
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();
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