Copied to clipboard

Flag this post as spam?

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


  • DanO 5 posts 26 karma points
    Apr 26, 2010 @ 20:52
    DanO
    0

    How do you render a custom datatype (e.g. - a dropdown) from a .NET control?

    I have created a number of new data types (mostly dropdowns) to use as the properties of a custom data type.  I would like the template (or an associated macro) for this new document type to include a basic search form that includes those same dropdowns.  I found one post that explains how to re-create a custom dropdown datatype using XSLT:

    http://our.umbraco.org/forum/developers/xslt/3676-Displaying-a-dropdown-list-(data-type)-on-a-public-page-using-XSLT

    But this seems like re-inventing the wheel to me.  Isn't there a .NET control - something like <umbraco:DataType id="datatypeid" /> that would allow me to render my custom dropdown datatype exactly as it is being rendered by the back office?  Obviously umbraco already has a framework for building HTML / .NET controls, and I would prefer to leverage that rather than re-creating controls from scratch everytime I need one. 

    Any insight anyone can offer would be greatly appreciated!

    Thanks, DanO

  • DanO 5 posts 26 karma points
    Apr 26, 2010 @ 23:02
    DanO
    1

    An update for anyone that is interested -

    I was able to figure out how to generate the control via .NET, with help from this post:

    http://our.umbraco.org/forum/developers/api-questions/8011-Empty-control-values-in-frontend

    Here's some stripped down code that can be inserted into a template to demo the functionality, but to actually do anything useful you would of course want to create an .acsx or server control with event handlers, etc.  In my case the drop down I want to render has a data type id of 1125 - you can locate the id for the data type you are trying to render in the datatypeNodeId column of the cmsDataTypePreValues table.

    <%@ Import Namespace="umbraco.editorControls" %>
    <%@ Import Namespace="umbraco.cms.businesslogic.datatype" %>

    <% 
     DataTypeDefinition dt = DataTypeDefinition.GetDataTypeDefinition(1125);   
     dropdown dd = (umbraco.editorControls.dropdown)dt.DataType.DataEditor;
     ph.Controls.Add(dd);
     %>

     <asp:PlaceHolder ID="ph" runat="server" />

    -DanO

Please Sign in or register to post replies

Write your reply to:

Draft