Copied to clipboard

Flag this post as spam?

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


  • Iain 8 posts 72 karma points
    Dec 02, 2009 @ 12:39
    Iain
    0

    Custom Control Properties

    Hi,

    I am new to Umbraco and I have created a .Net custom control to use in an Umbraco page.

    The control has a property on it:

    public ImageSize ImageSize { get; set; }

    which is of type ImageSize defined as:

    public enum ImageSize
    {
            ExtraLarge,
            Large,
            Medium,
            Small
    }

    It all appears to load into umbraco correctly, and is added to a page as follows:

     <umbraco:Macro HotelId="578"
            HFCServiceEndpoint="http://testserver/HotelService/HotelService.svc"
            ImageSize="ExtraLarge"
            Alias="HFCViewer"
            runat="server">

    but when I load the page containing the control I get the following error:

    Error loading customControl (Assembly: GoldMedal.Common.Web.UI, Type: 'GoldMedal.Common.Web.UI.HotelContent.HotelContentViewer'
    Invalid cast from 'System.String' to 'GoldMedal.Hotels.HotelFormalContent.Assemblies.Contracts.DataContracts.ImageSize'.
      at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
      at System.String.System.IConvertible.ToType(Type type, IFormatProvider provider)
      at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
      at umbraco.macro.loadControl(String fileName, String controlName, Hashtable attributes, Hashtable pageElements)
      at umbraco.macro.renderMacro(Hashtable attributes, Hashtable pageElements, Int32 pageId)

    I am guessing that I could fix this by changing the public property to a string and parsing the value in the set method of the property. But this feels like a bit of a hack and I would rather do it "properly" if possible.

    Is there a way that to use enums as public properties?? Or any custom class for that matter?

    Thanks for any help,

    Iain

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 02, 2009 @ 12:50
    Dirk De Grave
    0

    Hi

    Short term solution: define property as string (or even better as string) as cast to enum value in your setter!

    Long term solution: create a new macro property type (Haven't done nor tested that, so not sure if this would work) A macro property type is type of macro property selected from the dropdown (in parameters tab on macro)

     

    Hope this helps.

    Regards,

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft