More in this section

Forums / Developing with Sitefinity / Caption property for MetaInfo?

Caption property for MetaInfo?

9 posts, 0 answered
  1. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    17 Nov 2008
    Link to this post
    Hi,

    Since Caption is a member of IMetaInfo, it seems like I should be able to set the caption for an item in the metaFields section of web.config:

    <add 
        
    key="Products.Category" 
        caption="My Caption" 
        
    valueType="ShortText" 
        
    visible="True" 
        
    searchable="True" 
        
    sortable="True" 
        
    defaultValue="" />


    Am I missing something?

    Thanks in advance,
    Mike
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 Nov 2008
    Link to this post
    Hi Mike,

    Thank you for using our services.

    Caption attribute cannot be added in the web.config file. Generally, the caption dynamically replace underscore from the meta key name with a space and this is the reason why the attribute cannot be set in the templates for a module. We will extend the functionality of the property in one of the next releases.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    17 Nov 2008
    Link to this post
    Thanks for the info, Ivan. 

    I take it, then, that there is no way to change the display name for a built-in item like Category?  I can change it in the resource files everywhere else, but not in the ControlPanelEdit.ascx view panel, where it's displayed as part of the details repeater:

    <asp:Repeater ID="repeaterItemMetaData" runat="server">


    Thanks,
    Mike
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    19 Nov 2008
    Link to this post
    Hi Mike,

    Thank you for getting back to me.

    You can try adding a code behind to the templates and add a code that sets a new name of the metadata.
    Here is an example where we are changing the Category metafield to My Category.

    public partial class ControlPanelEdit : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            repeaterItemMetaData.ItemDataBound += new RepeaterItemEventHandler(repeaterItemMetaData_ItemDataBound); 
        } 
     
        void repeaterItemMetaData_ItemCreated(object sender, RepeaterItemEventArgs e) 
        { 
            if (e.Item.ItemType == ListItemType.Item) 
            { 
                IMetaInfo meta = e.Item.DataItem as IMetaInfo; 
                if (meta != null && meta.Key == "Category"
                { 
                    ITextControl label = e.Item.FindControl("lblKey"as ITextControl; 
                    if (label != null
                    { 
                        label.Text = "My Category"
                    } 
                } 
            } 
        } 


    I hope this helps.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    19 Nov 2008
    Link to this post
    Ah, that's a great idea.  Thanks!

    Mike
  6. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    20 Nov 2008
    Link to this post
    Hi Ivan,

    I'm having a couple problems with the example you provided...one was easy to fix, but a solution to the other is eluding me.

    First, the example shows the ItemDataBound delegate getting registered in the Page_Load method, which happens after the databinding has occurred.  ( I presume the handler being named ItemCreated was a typo).  That was easily solved by declaratively registering the handler in the repeaterItemMetaData tag:

    <asp:Repeater ID="repeaterItemMetaData"
        OnItemDataBound="repeaterItemMetaData_ItemDataBound"
        runat
    ="server">


    Now however, I find that the IMetaInfo meta object is always null (I guess because I can't cast a KeyValuePair to IMetaInfo).

    What I can't figure out is how to cast the e.Item.DataItem to something useful.

    If can figure this out, I think I can do several things that I'd like to get accomplished; 1. change the caption of metafields, and 2., where I'm storing the URL of a thumbnail, construct an image tag in the repeater.

    Any idea what's wrong?

    Thanks again!

    Mike
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    20 Nov 2008
    Link to this post
    Hello Mike,

    I debugged the code from my last reply and I noticed the same things as you. Cast to KeyValuePair did not help. The solution is using of onPreRender method. Check out the code below.

    using System; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
     
    public partial class Sitefinity_Admin_ControlTemplates_News_ControlPanelEdit : System.Web.UI.UserControl 
        //call onPreRender method 
        protected override void OnPreRender(EventArgs e) 
        { 
            base.OnPreRender(e); 
     
            foreach (RepeaterItem item in this.repeaterItemMetaData.Items) 
            { 
                //replace the text of the control with ID="lblKey" if label text = "Category" 
                ITextControl label = item.FindControl("lblKey"as ITextControl; 
                if (label != null && label.Text == "Category"
                { 
                    label.Text = "New Category Name"
                } 
            } 
        } 


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Mike
    Mike avatar
    208 posts
    Registered:
    10 Dec 2007
    21 Nov 2008
    Link to this post
    Thanks Ivan,

    That does work, although I'd sure like to figure out why the cast didn't work. My biggest problem so far is that I can't seem to figure out how the Generic Content item is organized, and how to databind with the metafields directly.  This would probably be much easier to figure out if I had access to the source code of the Product module's equivalent of ControlPanelEdit.ascx.cs, so that I could see how the databinding is  handled by the generic content module codebehind. 

    This thread has begun to converge with another one I have running on changing the order of the metaFields.  I appologize for the duplication, and figured I'd put a link to that thread here:

    http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-btekgt.aspx

    That thread has my code for a very hackish solution to the problem, so maybe it will help someone else. 

    Regards,
    Mike Sharp
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Nov 2008
    Link to this post
    Hello Mike,

    Thank you for getting back to me and sharing the link to the other thread. I also believe that it will be useful to the other community members.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

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