Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevon K. Hayes 255 posts 281 karma points
    May 04, 2010 @ 03:29
    Kevon K. Hayes
    0

    How do I get DocumentType Property Values out of Umbraco Into My User Control

    I have a documentType that has 2 properties.  I want to use the value of those properties in my user control,  and I want to accomplish this in the "code behind" of my user control  e.g. :

    <div id="UmbProperty1Output">
         <% theValueOfAnUMBDocTypeProperty %>
    </div>

    I realize I need to reference the proper UMB .DLLs in my project & expose the DocType Property Value in a public property.  However I need to get the value of the property before I can expose it. 

    Thanks in advance UMB Experts.

  • Tobias Neugebauer 52 posts 93 karma points
    May 04, 2010 @ 09:50
    Tobias Neugebauer
    0

    Hi

    this is what i would do: Add two Propertys to your UserControl the first is to get the current Page Id

    public int PageId 
    {
        get { return Convert.ToInt32( Context.Items[ "pageID" ] );}
    }

    the second is to get the value of your property (replace "MY_PROPERTY" with the correct name!):

    public string MyPropValue 
    {
        get
        {
            umbraco.cms.businesslogic.web.Document currentDoc =
                new umbraco.cms.businesslogic.web.Document(PageId);

            umbraco.cms.businesslogic.property.Property prop =
                currentDoc.getProperty( "MY_PROPERTY" );

            if( prop == null || prop.Value == DBNull.Value )
                return string.Empty;

            return prop.Value.ToString();
        }
    }

    After that you can use the code in your question to bind the Value.

    Hope this helps

    Toby

     

  • Jesper Hauge 298 posts 487 karma points c-trib
    May 04, 2010 @ 10:45
    Jesper Hauge
    1

    You can access the current node from umbraco.presentation.nodeFactory.Node like this:

    using umbraco.presentation.nodeFactory;
    
    namespace your_project.masterpages
    {
        public partial class YourPage : MasterPage
        {
            private readonly Node _currentNode = Node.GetCurrent();
    
            protected void Page_Load(object sender, EventArgs e)
            {
                myLiteral.Text = _currentNode.GetProperty("yourPropertyName").Value;
            }
        }
    }

    Regards
    Jesper Hauge

  • Thomas Höhler 1237 posts 1709 karma points MVP
    May 04, 2010 @ 11:21
    Thomas Höhler
    2

    Hi,

    in the frontend avoid the usage of the umbraco.cms.businesslogic.web.document cause this makes more than one call to the db. As Jesper mentioned use the umbraco.presentation.nodeFactory namespace. Dirk has a good blog post on this: http://www.netaddicts.be/articles/document-api-vs-nodefactory.aspx

    hth, Thomas

  • Tobias Neugebauer 52 posts 93 karma points
    May 04, 2010 @ 11:25
    Tobias Neugebauer
    0

    and again learned something ;)

    thank you guys!

  • Kevon K. Hayes 255 posts 281 karma points
    May 04, 2010 @ 16:33
    Kevon K. Hayes
    0

    Thanks guys I'll attempt the solutions today and report my feedback... I'll of course spread the love when by voting.

  • Casey Neehouse 1339 posts 483 karma points MVP 2x admin
    May 04, 2010 @ 20:25
    Casey Neehouse
    0

    Another simple option:  umbraco.library.GetItem('alias')

     

     

Please Sign in or register to post replies

Write your reply to:

Draft