Howto add controls at runtime to zones?

Topics: Developer Forum, User Forum
Jul 14, 2008 at 12:26 PM
Hey,

1. is it possible to add (user-)controls (inherited from n2 or base) at runtime to zones?

2. How did the recursive zone works in the template subproject?

Br

Oliver
Coordinator
Jul 14, 2008 at 4:15 PM
1. Sure, there lots of ways. Can you explain what you're after?
2. When determining which parts are added the control gets the list of parts from the CurrentPage.GetChildren("ZoneName") method. In the templates the base class overrides this method like this:

        public override ItemList GetChildren(string childZoneName)
        {
            ItemList items = base.GetChildren(childZoneName);
            if (childZoneName.StartsWith("Recursive") && Parent is AbstractContentPage)
            {
                items.AddRange(Parent.GetChildren(childZoneName));
            }
            return items;
        }

If the zone starts with the string "Recursive" it continues to add items added to parent pages.
Jul 15, 2008 at 5:29 PM
Hey,

2. ok. i understand.
1. I have a masterpage with a content placeholder and some zones. Als n2 pages use the masterpage. I have productpages, contactpages, listpages, etc. Only on the productpages i need to add a basket control to a zone called "container". I don't want to assign to all my productpages (about 1500) an extra control to the zone .

br

Oliver
Coordinator
Jul 16, 2008 at 6:54 AM
I think a recursive zone would work in your case. Create a zone definition (AvailableZone["RecusiveContainer"]) on the page containing your products. Then add a <n2:Zone ZoneName="RecursiveZone"... on the product templates. If GetChildren(string zoneName) works like it does in the templates you can add parts to the continer and they will appear on the products.


obeckers wrote:
Hey,

2. ok. i understand.
1. I have a masterpage with a content placeholder and some zones. Als n2 pages use the masterpage. I have productpages, contactpages, listpages, etc. Only on the productpages i need to add a basket control to a zone called "container". I don't want to assign to all my productpages (about 1500) an extra control to the zone .

br

Oliver