More in this section

Forums / Developing with Sitefinity / Custom meta fields don't work

Custom meta fields don't work

9 posts, 0 answered
  1. fregas baratis
    fregas baratis avatar
    185 posts
    Registered:
    14 Nov 2002
    23 Dec 2008
    Link to this post
    I'm using Sitefinity 3.5.  I think its the latest release.

    I'm following this article to add my own fields to the Document Library:
    http://www.sitefinity.com/help/developer-manual/how-to-gc-based-add-custom-meta-fields.html

    I added the regionID field as a drop down list to the ContralPanelEdit.ascx file for Libraries:

    <sfGCn:ContentMetaFields ID="editMetaFields" runat="server">
                        <ItemTemplate>
                            <h3>
                                <asp:Literal ID="Literal11" runat="server" Text="<%$Resources:Details %>"></asp:Literal></h3>
                            <fieldset class="set">
                                <ol class="setIn">
                                    <li>
                                        <asp:Label ID="Label7" AssociatedControlID="Author" runat="server" Text="<%$Resources:Author %>"></asp:Label>
                                        <asp:TextBox runat="server" ID="Author"></asp:TextBox>
                                    </li>
                                    <li>
                                        <asp:Label ID="Label5" runat="server" AssociatedControlID="Description" Text="<%$Resources:DocumentDescription %>"></asp:Label>
                                        <asp:TextBox runat="server" ID="Description" TextMode="MultiLine"></asp:TextBox>
                                    </li>
                                    <li>
                                         <asp:Label ID="RegLabel" runat="server" AssociatedControlID="RegionID" Text="Region"></asp:Label>
                                       <asp:DropDownList runat="server" ID="RegionID">
                                            <asp:ListItem Text="" Value=""></asp:ListItem>
                                            <asp:ListItem Text="North" Value="N"></asp:ListItem>
                                            <asp:ListItem Text="South" Value="S"></asp:ListItem>
                                            <asp:ListItem Text="Southwest" Value="SW"></asp:ListItem>                                   
                                        </asp:DropDownList>
                                     </li>
                                </ol>
    ...

    And i added this to my web.config under <metaFields>

    <add key="Libraries.RegionID" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="" />

    I see the field when I edit an image or document, but it won't save.

    Help!

    Thanks,
    Craig



  2. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    23 Dec 2008
    Link to this post

    You need to implement the ITextControl interface in your dropdown control, and assign the selected value of the dropdown to the text property.  The metadata code that wires up custom metafields only works with text controls. 

    Here's an example (using a radio button, but it's very close to what you want to do).  First, I have a custom meta property for wine_type:

    <add key="Products.Wine_Type" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue=""/>


    In ControlPanelEdit.ascx, I have a tag for a custom user control with an ID of Wine_Type, which maps to my meta property. 

     

    <li> 
        <asp:Label ID="lblWineType" runat="server" Text='<%$Resources:WineType %>' AssociatedControlID="Wine_Type"></asp:Label> 
        <CPi:WineType ID="Wine_Type" runat="server" /> 
    </li> 
     

    This is the control:


    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="WineType.ascx.cs" Inherits="UserControls_Products_WineType" %> 
     
    <fieldset id="WineTypeWrapper">  
        <asp:RadioButtonList ID="WineTypeRadioList" runat="server"  CssClass="WineType_RadioButton_list">  
            <asp:ListItem>Red</asp:ListItem> 
            <asp:ListItem>White</asp:ListItem> 
            <asp:ListItem>Sparkling</asp:ListItem> 
        </asp:RadioButtonList> 
    </fieldset> 
     


    And in the Codebehind, I implement the ITextControl interface.  But since it's not text control, Sitefinity looks for a public Text property when trying to update the metaproperty in the GC item.  I set that to the selected value of my dropdown, and presto, it works.


    using System;  
    using System.Collections;  
    using System.Configuration;  
    using System.Data;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.HtmlControls;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
     
    public partial class UserControls_Products_WineType : System.Web.UI.UserControl, ITextControl  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
     
        }  
     
        #region ITextControl Members  
     
        public string Text  
        {  
            get  
            {  
                return WineTypeRadioList.SelectedValue;  
            }  
            set  
            {  
                WineTypeRadioList.SelectedValue = value;  
            }  
        }  
     
        #endregion  
     
     
    }  
     
     
     
  3. fregas baratis
    fregas baratis avatar
    185 posts
    Registered:
    14 Nov 2002
    27 Dec 2008
    Link to this post
    You know I tried using a custom control that implemented ITextControl, but it didn't seem to work.

    i'll try it again and get back to you.

    thanks for your help,
    craig
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    29 Dec 2008
    Link to this post
    Hello,

    You should use the IText interface indeed.
    Please try it again and follow up if you still have any problems.

    All the best,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. fregas baratis
    fregas baratis avatar
    185 posts
    Registered:
    14 Nov 2002
    29 Dec 2008
    Link to this post
    Hello All,

    I implemented the ITextControl interface exactly the way you described and it still did  not work.  I believe this is a bug in the Libraries module.  I took my same control and put it in the ControlPanelEdit for the News module instead, added the meta tag to the web.config, and it worked INSTANTLY.  My extra field saved and pre-populated just fine and even showed up in the admin where you view the news item.  It only fails to save in the Libraries. 

    Just in case I did something wrong, I'm pasting in the code I used for the libraries.  If this is indeed a bug in Sitefinity, can I get a patch for this ASAP?

    Thanks,
    Craig

    In Web.Config:

    <add key="Libraries.RegionID" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="0" />

    In /sitefinity/admin/controltemplates/libraries/ControlPanelEdit.ascx:

    <%@ Register TagPrefix="uc" Src="~/RegionSelector.ascx" TagName="region" %>
    ...

    my control is inside the tags: <sfGCn:ContentMetaFields ID="editMetaFields" runat="server"><ItemTemplate>


                                    <li>
                                        <asp:Label ID="RegLabel" runat="server" AssociatedControlID="RegionID" Text="Region"></asp:Label>
                                        <uc:region runat="server" id="RegionID" />
                                       
                                           
                                       
                                    </li>

    My control code is here:

    <asp:DropDownList runat="server" ID="RegionIDDrop">
        <asp:ListItem Text="" Value=""></asp:ListItem>
        <asp:ListItem Text="North" Value="1"></asp:ListItem>
        <asp:ListItem Text="South" Value="2"></asp:ListItem>
        <asp:ListItem Text="Southwest" Value="3"></asp:ListItem>
    </asp:DropDownList>


    public partial class RegionSelector : System.Web.UI.UserControl, ITextControl
        {
            public string Text
            {
                get
                {
                    return this.RegionIDDrop.SelectedValue ;
                }
                set
                {
                    this.RegionIDDrop.SelectedValue = value;
                }
            }
            protected void Page_Load(object sender, EventArgs e)
            {

            }
        }
  6. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    29 Dec 2008
    Link to this post
    Hi Craig,

    For libraries, there seems to be one additional step that I wasn't aware of (I've never done this for the libraries module).  They're a bit different from the other modules, as they have different kinds of libraries, and each one can have different kinds of metadata.  So you have to add the metakey to the telerik/libraries/libraryInfo entry for your library type. I haven't tested this, though.  If this doesn't help, you might file a support ticket.

    <add name="Document" 
            
    title="Document Library" 
            defaultExtenstions
    =".doc, .docx, .rtf, .txt, .pdf, .ppt, .pptx, .html, .xls, .xlsx" 
            
    metaKeys="Author, Description, Extension, Name, Size, Category, RegionID">

    </add>

  7. fregas baratis
    fregas baratis avatar
    185 posts
    Registered:
    14 Nov 2002
    29 Dec 2008
    Link to this post
    That did the job!  Thanks!

    This should be in the Sitefinity documentation.  I would have never thought of doing this.

    Craig
  8. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    29 Dec 2008
    Link to this post
    Actually, I'm surprised I found it myself.  I only figured it out because I saw a post where they said they were going to update the news module to add the ability to have different metadata for different kinds of news items... 

    Glad you got it working!

    Mike
  9. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    30 Dec 2008
    Link to this post
    Hello,

    Well I am really glad that everything is fine! It is actually in the User Manual->Working with Modules->Images and Documents->Customizing Images and Documents -> Adding Custom Meta Fields. Perhaps we should reorganize the manual though.

    Mike, we updated your account with some Telerik points!

    All the best,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
9 posts, 0 answered