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

Forums / Developing with Sitefinity / Adding Link To ListPageMaster.ascx

Adding Link To ListPageMaster.ascx

9 posts, 0 answered
  1. Mike Berlin
    Mike Berlin avatar
    16 posts
    Registered:
    19 Feb 2010
    02 Apr 2010
    Link to this post
    Hello,

    I'm attempting to add a mailto link in the ListPageMast.ascx that contains the title of the news item in the href.  This is the code I'm trying and I'm getting the error:

    The resource object with key 'Title' was not found.

    <a href="mailto:email@address.com?subject=Applying For <asp:Literal ID='litApplyLink' runat='server' Text='<%$Resources:Title %>' />&Body=Please make sure to attach your resume to this email">Apply Now</a>

    Is there a listing of items available that can be used like <%$Resources:FullStory %>?  I would think the title would be a part of this collection so I don't have to write a custom control just to add the title inside of a link.  Any ideas?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Apr 2010
    Link to this post
    Hi Mike Berlin,

    The errors you are getting is thrown, because you  do not have "Title" resource in the resx file for ListPageMaster. ascx template. You can fix the error by adding the resource name into resx file. You could take a look at Basic Instincts: Resources and Localization in ASP.NET

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Mike Berlin
    Mike Berlin avatar
    16 posts
    Registered:
    19 Feb 2010
    06 Apr 2010
    Link to this post
    Thanks for the reply Ivan.  If I place Title within the .resx file will that pull the title from the news item automatically?  I'm wanting to pull the news item title to be used within the mailto link.  Perhaps there's a better method to accomplish this?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Apr 2010
    Link to this post
    Hi Mike Berlin,

    When you change the culture the Title should be set depending on the current culture and resx key values.

    I'm wanting to pull the news item title to be used within the mailto link.


    Since the news items are dynamically created it does not make sense to make resx file for each title. The News module supports localization (you could set allowLocalization="true" in the web.config's provider declaration) and you can localize the Title metakey as well ( set localizable ="true" for he metakey)

    <add key="News.Title" localizable="true" valueType="ShortText" visible="True" searchable="True" sortable="True" defaultValue="Title" mandatory="True"/>

    You could create a custom control that inherits from NewsView. You could override SetItemContent or SetItemMetaData method and set the content item metakey - Title to the MailTo link.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Mike Berlin
    Mike Berlin avatar
    16 posts
    Registered:
    19 Feb 2010
    07 Apr 2010
    Link to this post
    You could create a custom control that inherits from NewsView. You could override SetItemContent or SetItemMetaData method and set the content item metakey - Title to the MailTo link.

    Would you be able to provide sample code or direct me to a how-to for this suggestion?  I think this would be the best solution.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Apr 2010
    Link to this post
    Hello Mike Berlin,

    Below is a sample code that illustrates how to override the control and get the metadata for the content item

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.News.WebControls;
    using System.Web.UI.WebControls;
    using System.Web.UI;
     
    /// <summary>
    /// Summary description for NewsViewCustomControl
    /// </summary>
    public class NewsViewCustomControl : NewsView
    {
     
        public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/News/ListPageMaster.ascx";
            }
     
        }
     
        public override string SingleItemTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx";
            }
     
        }
     
        
        protected override void SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
        {
            base.SetItemMetadata(itemContainer, contentItem);
         
        }
     
        protected override void SetItemContent(Control itemContainer, Telerik.Cms.Engine.IContent contentItem)
        {
            base.SetItemContent(itemContainer, contentItem);
     
           string cntTitle = (string)contentItem.GetMetaData("Title")
        }
    }


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Mike Berlin
    Mike Berlin avatar
    16 posts
    Registered:
    19 Feb 2010
    07 Apr 2010
    Link to this post
    I was able to find a solution.  This is the code I ended up using on the ~/Sitefinity/ControlTemplates/News/ListPageMaster.ascx:

    <a href="mailto:email@address.com?subject=<asp:Literal runat='server' Text='<%# ((CmsContentBase)Container.DataItem).GetMetaData("Title").ToString().Replace("&", "%26")%>' /> - Job Application&body=Please make sure to attach your resume when applying for this position.">Apply Now</a>

    I added the Replace because some job titles had & in the title which was throwing off the body querystring argument for the mailto link.

    There was no need to extend the control because I was able to access the Title using the built in meta data.  Is there a way to see all the items that accessible via metadata?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Apr 2010
    Link to this post
    Hi Mike Berlin,

    All metakeys are defined( and can be defined) in the web.config <Metafields> node. Your approach works, but if you need to get better results - expose some public properties to set the metafields values.

    I hope that this helps.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Mike Berlin
    Mike Berlin avatar
    16 posts
    Registered:
    19 Feb 2010
    07 Apr 2010
    Link to this post
    Great.  Thanks for the help Ivan!
Register for webinar
9 posts, 0 answered