1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / GetMetaData in UserControl

GetMetaData in UserControl

11 posts, 0 answered
  1. Christian
    Christian avatar
    20 posts
    Registered:
    12 Mar 2008
    16 Sep 2009
    Link to this post
    Hi, we are including a usercontrol in a view (template).

    How can we use the API to fetch MetaData by key for the specific item ?

    I know this is done via IContent, but I do not get in touch with it inside a UserControl.

    Thanks
    Chris
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    16 Sep 2009
    Link to this post
    Hi Christian,

    if this is a template for a public control that inherits from ContentView your control  should have the same ID as the name of your metakey ( for  instance <asp:Label Id="Title" runat="server"/>)
    if you are using a backend view you can wrap the control inside ContentMetafields control and again use the same ID.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Christian
    Christian avatar
    20 posts
    Registered:
    12 Mar 2008
    16 Sep 2009
    Link to this post
    Hi,

    thanks, but we need the value of a metadatafield in codebehind inside the usercontrol for the specific item that is loaded by the view (item) and hold that usercontrol.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    16 Sep 2009
    Link to this post
    Hi Christian,

    As you noticed there are two types of templates. In which one you are going to use your user control and how? Are you going to drip in on the page through Sitefinity's  interface?

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Christian
    Christian avatar
    20 posts
    Registered:
    12 Mar 2008
    16 Sep 2009
    Link to this post
    sorry... we created a custom generic content based module and we are using the usercontrol in a public view template overriden by custom template logic (sitefinity/controltemplates folder).

    We want to get the values in that usercontrol by codebehind / api.

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    16 Sep 2009
    Link to this post
    Hello Christian,

    ..neric content based module and we are using the usercontrol in a public view template...

    This means that you have a control that derives from ContentView, where you can override SetitemMetadata method where you have access to the content item object.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Christian
    Christian avatar
    20 posts
    Registered:
    12 Mar 2008
    17 Sep 2009
    Link to this post
    ho, ok, but we want to get the metadata inside the usercontrol codebehind... Can we get in touch there with the metadata?
  8. Tobi
    Tobi avatar
    3 posts
    Registered:
    17 Sep 2009
    17 Sep 2009
    Link to this post
    Hi, I think I have the equal problem.

    I need the access to metadata in usercontrol codebehind, too.
    I have a ViewItemList and I want to change the output of each listelement dependent on metadata.
    An example: If a Metadata-field is empty, a Icon should be hidden and so on.

    Thanks
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    17 Sep 2009
    Link to this post
    Hi,

    Christian
    It is not possible to get the metadata from user
    control . The only way to do this is when singe item is listed on your page and you use ID in the urlRewriteFormat. So that you can get the ID from a QueryString.

    Tobi
    If a metadata for a content item is empty and you do not want to show an icon you can use the "String Format" option under ContentView designer, step 3.  For instance if you use "{0}" as a string format.
    Another option is creating a custom control that inherits from desired ContentView based control and overriding SetItemMetaData method.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. Tobi
    Tobi avatar
    3 posts
    Registered:
    17 Sep 2009
    18 Sep 2009
    Link to this post
    Hi Ivan,

    thank you for your tip.

    I use a custom control and override the SetItemMetaData method. Now I can access to the Metadata and the Controls on the listpage, like this:
             
     
                Image picture = itemContainer.FindControl("Picture") as Image; 
                if (picture != null) 
               { 
                    picture.ImageUrl = contentItem.GetMetaData("Picture").ToString(); 
                    pictureqAlternateText = contentItem.GetMetaData("Picture_Title").ToString(); 

    But on the detailpage, the Controls of the page are not found. In the example above, the picture are always null. Can I not used SetItemMetaData on the detailpage?

    Thank you for any tips.





  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    18 Sep 2009
    Link to this post
    Hello Tobi,

    Most probably you have not added the Image control with Id="Picture" to the details template (ListPageDetails) and it cannot be found.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
11 posts, 0 answered