Copied to clipboard

Flag this post as spam?

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


  • Emil Christiansen 66 posts 148 karma points
    Mar 05, 2014 @ 10:26
    Emil Christiansen
    0

    Getting the Name or Alias on property from UserControl

    Hi There!

    I have created a datatype "MyDataType" of the type "Umbraco Usercontrol Wrapper" which wraps a usercontrol called "MyUserControl.ascx".

    On a document type i have added a property with the name "Hello" and alias "hello" of the type "MyDataType".

    Is it in anyway possible to get the alias and name of the property from the codebehind when the usercontrol MyUserControl is loaded?

    This is Umbraco 6.1.6

    Thanks in advance!

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 05, 2014 @ 11:18
    Bo Damgaard Mortensen
    0

    Hi Emil,

    You should be able to get a reference to the current IPublishedContent like so:

    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    var nodeId = int.Parse(HttpContext.Current.Request.QueryString["id"]);
    var currentNode = umbracoHelper.TypedContent(nodeId);

    // Get fields from node
    var propertyValue = currentNode.GetPropertyValue<string>("hello");

    // Not entirely sure if the UmbracoHelper has got a corresponding method for this. Also not sure if IPublishedContent's alias property is called "Alias" or "NodeTypeAlias" or some such :-)
    var propertyAlias = library.GetPropertyTypeName(currentNode.Alias, "hello"); 

    Let me know how this behaves.

    All the best,

    Bo

  • Emil Christiansen 66 posts 148 karma points
    Mar 05, 2014 @ 11:31
    Emil Christiansen
    0

    Hi Bo!

    I am not sure, but isn't it necessary to know the name of the property in your suggestion?

    I may be wrong :) ?

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Mar 05, 2014 @ 11:40
    Bo Damgaard Mortensen
    0

    Hi Emil,

    Yes, it's necessary to know the property alias using my code example. I take that wasn't what you needed? :-D

  • Emil Christiansen 66 posts 148 karma points
    Mar 05, 2014 @ 11:56
    Emil Christiansen
    0

    No :)

    Let's say I have 4 properties on the same document all of 'MyDataType' type but with different names and aliases:

    Name: Property1 - Alias: property1 Name: Property2 - Alias: property2 Name: Property3 - Alias: property3 Name: Property4 - Alias: property4

    The usercontrol is loaded 4 times when the document is rendered in the backoffice, and I want to be able to see the name and alias on the corresponding property each time the usercontrol is loaded e.g. in the page load method via the "object sender" parameter.

    Does it make any sense :) ?

Please Sign in or register to post replies

Write your reply to:

Draft