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

Forums / Developing with Sitefinity / Add Custom Meta Fields Example

Add Custom Meta Fields Example

4 posts, 0 answered
  1. Sheridan
    Sheridan avatar
    13 posts
    Registered:
    02 Jul 2008
    07 Aug 2008
    Link to this post
    I am trying to follow exactly the example "Add Custom Meta Fields" in the developer manual (http://www.sitefinity.com/help/developer-manual/how-to-gc-based-add-custom-meta-fields.html) with Sitefinity 3.2 SP2 1616 and I am not getting the expected result.  I think this may need to be updated for the new controls.

    Everything works as expected on the Admin side, however when I get to the step
    "Displaying Meta Field Values on Public Controls" I copied the code exactly as it appears:

    <asp:HyperLink ID="PDFAttachment" runat="server" NavigateUrl='<% = this.Text %>'></asp:HyperLink>

     and placed it in ~/Sitefinity/ControlTemplates/News/Modes/ListPageMaster.ascx.  This is where I think the disconnect might lie, as placing the Hyperlink tab in ~/Sitefinity/ControlTemplates/News/SingleNews.ascx does not seem to have any effect whatsoever on the output of my NewsView control.  However, when I place it in ListPageMaster.ascx I end up with a link with:

     href="Sitefinity/ControlTemplates/News/Modes/%3C%25%20=%20this.Text%20%25%3E"

    This just resolves to:

    Sitefinity/ControlTemplates/News/Modes/<%25 = this.Text %25>

    and gives me a page not found error.

    Any help on this would be appreciated
    Sheridan





  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    08 Aug 2008
    Link to this post
    Hi Sheridan,

    SingleNews.ascx is an obsolete template and if you are using the new control called NewsView.ascx it will have no effect as you've said because the template is not used. The reason you are getting the URL as you do is in the fact that ASP.NET by default uses VB.NET and "this" is a C# keyword (yes, we need to clarify this in the manual - sorry). To go around this, you can do one of the two following things:

    1. Change "this" to "Me" which is VB.NET keyword:
    <asp:HyperLink ID="PDFAttachment" runat="server" NavigateUrl='<% = Me.Text %>'></asp:HyperLink>   
     
    2. Change the language of the template (ListPageMaster.ascx) by adding this at the top of the file:
    <%@ Control Language="C#" %> 

    While this should work, admittedly this approach is rather limited. I've developed a sample control on my blog that you can use to map any meta field value to any property of any control inside a template. You can find more about this control and download it from here:
    http://blogs.sitefinity.com/Ivan/Post/08-07-03/metamaster_2008_finally_released_.aspx

    I hope you'll find this information helpful. Let us know if there is anything else we can do for you.

    Regards,
    Ivan
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Sheridan
    Sheridan avatar
    13 posts
    Registered:
    02 Jul 2008
    08 Aug 2008
    Link to this post
    Thanks for the quick reply Ivan.  Changing the this.Text to Me.Text resulted in an unhandled exception with the error:

    Compiler Error Message: BC30456: 'Text' is not a member of 'ASP.sitefinity_controltemplates_news_modes_listpagemaster_ascx'.


    Thanks
    Sheridan


  4. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    11 Aug 2008
    Link to this post
    Hello Sheridan,

    I am sorry that my first suggestion didn't work. If you need more flexibility you can still go with the second option from my last post or rewrite your code to look like this:

    <asp:HyperLink ID="PDFAttachment" runat="server" NavigateUrl='<% = DataBinder.Eval(Container.DataItem, "PDFAttachment") %>'></asp:HyperLink> 

    I hope you'll find this information helpful. Let me know if there is anything else we can do for you.

    Best wishes,
    Ivan
    the Telerik team

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