Recursive paameters from page properties in .NET user controls Options
acullen
Posted: Friday, September 14, 2007 7:48:22 PM

Rank: Devotee

Joined: 4/13/2007
Posts: 57
Location: Arlington, VA
I'm building a system that the client needs to be able to open or close on their own. I'd like to be able to offer a page property called "isOpen" on the main page of the system. The problem I am having is that I am unable to access that property on subsequent pages in the system when calling the specific control each sub page requires. I've tried prefacing the umbraco property Aliases with both $ and # - neither seem to handle recursion.

Help!
acullen
Posted: Sunday, September 16, 2007 10:37:52 PM

Rank: Devotee

Joined: 4/13/2007
Posts: 57
Location: Arlington, VA
Nevermind - finally found the thread where this was discussed. However, now that I know I can't do this the simple way, let me ask about the hard way. Is there a way to programmatically search for a property up the tree in C#?
mortenbock
Posted: Monday, September 17, 2007 12:37:05 PM

Rank: Addict

Joined: 7/19/2006
Posts: 821
Location: Århus, Denmark
I'm not shure that there is any easy way to do this, other than check if the property is set on the current node, and then iterate up through the tree until a node contains a value for the property.

Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

mortenbock
Posted: Monday, September 17, 2007 12:38:14 PM

Rank: Addict

Joined: 7/19/2006
Posts: 821
Location: Århus, Denmark
Would be nice with a getProperty(string alias, bool recursive) method though...

Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

acullen
Posted: Tuesday, September 18, 2007 8:21:31 PM

Rank: Devotee

Joined: 4/13/2007
Posts: 57
Location: Arlington, VA
Hmmm. I'm willing to give it a try, but can someone tell me how to access the current node from my own custom usercontrol?
mortenbock
Posted: Tuesday, September 18, 2007 8:38:00 PM

Rank: Addict

Joined: 7/19/2006
Posts: 821
Location: Århus, Denmark
In C#
Code:

umbraco.presentation.nodeFactory.Node n = new umbraco.presentation.nodeFactory.Node.GetCurrent();


Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

acullen
Posted: Tuesday, September 18, 2007 9:25:16 PM

Rank: Devotee

Joined: 4/13/2007
Posts: 57
Location: Arlington, VA
Wow - fast! Thanks!
acullen
Posted: Wednesday, October 03, 2007 9:10:00 PM

Rank: Devotee

Joined: 4/13/2007
Posts: 57
Location: Arlington, VA
Just remembered this: here's the method in C#:

Code:

protected string GetRecursiveProperty(Node selectedNode, string propertyAlias)
        {
           
            Property p = selectedNode.GetProperty(propertyAlias);
            if (p != null)
                return p.Value;
            else
            {
                if (selectedNode.Parent != null)
                    return GetRecursiveProperty(selectedNode.Parent, propertyAlias);
                else
                    return null;
            }
        }


remember to include this line:
Code:

using umbraco.presentation.nodeFactory;
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.