This project is read-only.

ChildRedirect page

Topics: Developer Forum
Sep 21, 2008 at 1:43 PM
Sometimes, you need a temporary placeholder in your website until childs are added. For example, I have a products page. As long as there are no childs, the page should display normally. However, as soon as childs are added, the page should be a redirect.

Therefore, I created a page with the following source (extended from Redirect):

        protected override void OnInit(EventArgs e)
            // Check if this page has any children
            if (CurrentPage.Children.Count == 0)
                // Call base

                // Exit

            // Redirect to the first child

Maybe it's an idea to implement this in the Templates project?

Sep 21, 2008 at 3:57 PM
You mean for the news?

Just an idea: you also have the option of putting that logic in the content item by overriding the Url property to avoid a redirect.
Sep 21, 2008 at 4:06 PM
No, not for the news. The problem is basically my menu structure. I have this structure:

|- About us
|    |- About us
|    |- Resellers
|    |- Contact

My submenu is based on all the items of the same level, and the parent is the item on top of the current level. However, About us (1st one) should also show the submenu but doesn't because it's in a different level. However, it contains the same page information as the About Us (2nd one) because I don't want to write a page like:

"Welcome to About Us. Click here to go to About Us, click here to go to Resellers and click here to go to contact."

Another great example is services. Currently, I have only one page of services. However, in the future I will probably expand the services. I have added the ChildRedirect and implemented the services item (which is nothing more than a page explaining the services). As soon as I have multiple services, I can simply add a textpage and the multiple services will behave as a submenu.

As last example:

You are developing a new product and want to create a product placeholder. What you can do is create a ChildRedirect with the text: Soon, this product will be available. As soon as you add the download page (which is a subpage of the product), the "Soon, this product will be available" redirects to the first child (download) so the user can download the product.
Sep 25, 2008 at 12:07 PM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using N2.Templates.Items;

/// <summary>
/// Summary description for ProxyItem
/// </summary>
public class ProxyItem : AbstractContentPage, IStructuralPage
    public override string IconUrl { get { return "~/Lms/UI/Img/03/15.png"; } }
    [N2.Details.EditableTextBox("Url", 100)]
    public new string Url {
        get { return (string)this.GetDetail("TemplateUrl"); }
        set { this.SetDetail<string>("TemplateUrl", value); }

    public override string TemplateUrl { get { return this.Url; } }