Search code examples
user-controlsumbracoasp.net-controls

Add the Umbraco "siteName" textstring to my .net usercontrol


I have a text string property type that I use to display the "siteName" in the page title:

<title><umbraco:Item runat="server" field="siteName" recursive="true" /></title>

What code do I need in my .net usercontrol to add the "siteName"?

<asp:Label ID="siteName" runat="server" Text="siteName should go here!"></asp:Label>

Can anyone help?

I've added this to the Umbraco forum and was suggested the following, but not sure how to included it in my .ascx file:

dynamic node = new umbraco.MacroEngines.DynamicNode(umbraco.NodeFactory.Node.GetCurrent()); siteName.Text = node._siteName; 

Solution

  • You can use this in a usercontrol

    //var node = new Node(123); // Get node by Id, good if you have information on a certain page
    
    var node = Node.GetCurrent(); // Get the current node
    var nodeProperty = node.GetProperty("siteName").Value;
    siteName.Text = nodeProperty;