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

Forums / Developing with Sitefinity / Newslist paging

Newslist paging

24 posts, 0 answered
  1. Andreas
    Andreas avatar
    49 posts
    Registered:
    29 Dec 2007
    04 Feb 2008
    Link to this post
    Hi!

    Short question about the newslist module....while fixing the html for my newslist control I noticed that the linkbuttons and placeholder for nextpage, prevpage and pagenumbers arent picked up in the headertemplate (just the footertemplate). Is this by design or just something that's been missed?

    Preferable I'd liketo be able to chose wether to use the next, previous and pagenumbers in either the headertemplate or the footertemplate. Not that it cant be worked around but still.

    Thanks in advance.

    //Andreas
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    05 Feb 2008
    Link to this post
    Hello Andreas,

    It is by design. However, you could create your own custom or user control that will have the same functionality as the NewsList public control and implement your custom requirements in it.

    In the attachment you could find a simple example how to achieve this with a user control.

    Hope this helps.

    Best wishes,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Daniel L
    Daniel L avatar
    26 posts
    Registered:
    06 May 2006
    18 Feb 2008
    Link to this post
    Pepi,

    Is it possible for me to have a control that is essentially a "copy" of the News List control? I want to have the same settings as the news list control, rather than require the user to select the NewsList page like you made in this sample code. I was looking at extending the NewsList module with a different display template, but A) I need codebehind which doesnt look like you can put in templates, and B) I want the control to be selectable from the control box. if i make a new template it looks like the user has to type in the template URL in the NewsList module, which is too difficult for our end users. Basically I am trying to make a news list module that uses the RadRotator to display the articles.

    Thanks
    Daniel
  4. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    19 Feb 2008
    Link to this post
    Hi Daniel,

    If you want to use a RadRotator for displaying the news, I would recommend you create a User Control. In this case, you do not need a template to specify the layout of the control. Here is a simple example how to achieve this:

    .ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="NewsRotator.ascx.cs" Inherits="UserControls_NewsRotator" %> 
    <%@ Register Assembly="RadRotator.Net2" Namespace="Telerik.WebControls" TagPrefix="radR" %> 
     
    <radR:RadRotator ID="newsRotator" runat="server">  
        <FrameTemplate>  
            <div id="test">  
                <asp:HyperLink ID="thumbnailLink" runat="server" CssClass="astrong">  
                    <asp:Image ID="Thumbnail" runat="server"/>  
                </asp:HyperLink>  
            </div>  
            <div id="test2">  
                <asp:HyperLink ID="titleLink" runat="server" CssClass="astrong"
                    <asp:Label ID="newsTitle" runat="server"></asp:Label>  
                </asp:HyperLink>  
            </div>  
        </FrameTemplate>  
    </radR:RadRotator> 

    .cs
    using Telerik.News; 
    using Telerik.Cms.Engine; 
    using Telerik.WebControls; 
    using System.ComponentModel; 
    using Telerik.Cms.Web.UI; 
    using Telerik.Web; 
     
    public partial class UserControls_NewsRotator : System.Web.UI.UserControl 
        #region Public Properties 
     
        [Category("Data")] 
        public string ProviderName 
        { 
            get 
            { 
                if (String.IsNullOrEmpty(this.providerName)) 
                    this.providerName = NewsManager.DefaultContentProvider; 
                return this.providerName; 
            } 
            set 
            { 
                this.providerName = value; 
            } 
        } 
     
        [Browsable(true)] 
        public RadRotator Rotator 
        { 
            get 
            { 
                return this.newsRotator; 
     
            } 
            set 
            { 
                this.newsRotator = value; 
            } 
        } 
     
        [WebEditor("Telerik.Cms.Web.UI.UrlEditorWrapper, Telerik.Cms"), 
         Category("Behavior")] 
        public string SingleNewsPage 
        { 
            get 
            { 
                object obj = this.ViewState["SingleNewsPage"]; 
                if (obj != null
                    return (string)obj; 
                return String.Empty; 
            } 
            set 
            { 
                this.ViewState["SingleNewsPage"] = value; 
            } 
        } 
        #endregion 
     
        protected void Page_Load(object sender, EventArgs e) 
        { 
             
            if (this.manager == null
                this.manager = new NewsManager(this.ProviderName); 
     
            newsRotator.DataSource = manager.Content.GetContent(); 
            newsRotator.ItemDataBound += new Telerik.WebControls.RadRotator.RadRotatorItemEventHandler(newsRotator_ItemDataBound); 
            newsRotator.DataBind(); 
        } 
     
        void newsRotator_ItemDataBound(object sender, Telerik.WebControls.RadRotatorItemEventArgs e) 
        { 
            IContent cnt = (IContent)e.Item.DataItem; 
     
            (e.Item.FindControl("newsTitle"as Label).Text = cnt.GetMetaData("Title").ToString(); 
             
            string imgUrl = cnt.GetMetaData("Thumbnail"as string
            Image img = e.Item.FindControl("Thumbnail"as Image; 
     
            if (img != null
            { 
                if (!String.IsNullOrEmpty(imgUrl)) 
                    img.ImageUrl = imgUrl; 
                else 
                    img.Visible = false
            } 
     
            if (String.IsNullOrEmpty(this.baseUrl) && !String.IsNullOrEmpty(this.SingleNewsPage)) 
            { 
                this.baseUrl = this.SingleNewsPage; 
                int idx = this.baseUrl.LastIndexOf('.'); 
                if (idx > -1) 
                    this.baseUrl = this.baseUrl.Substring(0, idx); 
                if (!this.baseUrl.EndsWith("/")) 
                    this.baseUrl += "/"
            } 
     
            if (!String.IsNullOrEmpty(this.baseUrl)) 
            { 
                string url = String.Concat(this.baseUrl, 
                                           UrlRewriterService.FormatURL(cnt, manager.SettingsElement)); 
                IUrlService svc = UrlServices.GetService("LanguageService"); 
     
                if (svc != null
                    url = svc.ResolveLanguageUrl(url); 
     
                (e.Item.FindControl("thumbnailLink"as HyperLink).NavigateUrl = url; 
                (e.Item.FindControl("titleLink"as HyperLink).NavigateUrl = url; 
            } 
        } 
        #region Private Members 
     
        private string providerName; 
        private NewsManager manager; 
        private string baseUrl; 
        #endregion 

    Do let us know if you need any further assistance.

    Regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    19 Feb 2008
    Link to this post
    Hi Pepi,

    And how to link the custom provider "BrandNews" or the ListModule or the new ImageModule with this Rotator. Could you help-us.

    this.providerName = NewsManager.DefaultContentProvider;
    like
    this.providerName = BrandNewsManager.DefaultContentProvider;?
    regards
  6. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    20 Feb 2008
    Link to this post
    Hello Pierre,

    If you have created a custom News provider, you should specify its name (in your case BrandNews) as a value of the ProviderName property in the Properties window (have a look at the attachment for more information).

    As for using RadRotator with a List module, you should create a new User Control and implement the necessary functionality in it. You could use the provided NewsRotator.ascx User Control as an example of how to achieve this. Pay attention to the fact that your User Control should implement the IListDisplay interface.

    Hope this is helpful for you.

    Best wishes,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. Daniel L
    Daniel L avatar
    26 posts
    Registered:
    06 May 2006
    21 Feb 2008
    Link to this post
    Pepi,

    Thanks for code, it is very helpful. How would I go about letting the user select the news categories & tags to display on the rotator? I want them to be able to configure exactly what news to display from the rotator settings. (Just like the news list module).

    Thanks,
    Daniel
  8. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    22 Feb 2008
    Link to this post
    Hello Daniel,

    I am sorry but I am not sure I fully understand your question. Do you want to display tags and categories for the corresponding news in RadRotator, or is it something else you want to display? If I am right, here is an extended version of NewsRotator User Control:

    .ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="NewsRotator.ascx.cs" Inherits="UserControls_NewsRotator" %> 
    <%@ Register Assembly="RadRotator.Net2" Namespace="Telerik.WebControls" TagPrefix="radR" %> 
     
    <radR:RadRotator ID="newsRotator" runat="server">  
        <FrameTemplate>  
            <div id="thumbnailPnl">  
                <asp:HyperLink ID="thumbnailLink" runat="server">  
                    <asp:Image ID="thumbnail" runat="server"/>  
                </asp:HyperLink>  
            </div> 
            <div id="titlePnl">  
                <asp:HyperLink ID="titleLink" runat="server"
                    <asp:Label ID="newsTitle" runat="server"></asp:Label>  
                </asp:HyperLink>  
            </div>  
            <div id="categoryTagPnl"
                <asp:Literal ID="categoryLabel" runat="server" Text="Category:"></asp:Literal> 
                <asp:HyperLink ID="categoryNameLink" runat="server"
                    <asp:Label ID="categoryName" runat="server"></asp:Label>  
                </asp:HyperLink>  
                <br /> 
                <asp:Repeater ID="rptNewsTags" runat="server"
                    <HeaderTemplate> 
                        <dl><dt><asp:Literal ID="taggedWithLabel" runat="server" Text="Tagged With"></asp:Literal>:</dt> 
                    </HeaderTemplate> 
                    <ItemTemplate> 
                        <dd><asp:HyperLink ID="tagLink" runat="server"></asp:HyperLink></dd
                    </ItemTemplate> 
                    <FooterTemplate></dl></FooterTemplate> 
                </asp:Repeater> 
            </div> 
        </FrameTemplate>  
    </radR:RadRotator> 

    .cs
    using Telerik.News; 
    using Telerik.Cms.Engine; 
    using Telerik.WebControls; 
    using System.ComponentModel; 
    using Telerik.Cms.Web.UI; 
    using Telerik.Web; 
    using Telerik.Cms.Web; 
     
    public partial class UserControls_NewsRotator : System.Web.UI.UserControl 
        #region Public Properties 
     
        [Category("Data")] 
        public string ProviderName 
        { 
            get 
            { 
                if (String.IsNullOrEmpty(this.providerName)) 
                    this.providerName = NewsManager.DefaultContentProvider; 
                return this.providerName; 
            } 
            set 
            { 
                this.providerName = value; 
            } 
        } 
     
        [Browsable(true)] 
        public RadRotator Rotator 
        { 
            get 
            { 
                return this.newsRotator; 
     
            } 
            set 
            { 
                this.newsRotator = value; 
            } 
        } 
     
        [WebEditor("Telerik.Cms.Web.UI.UrlEditorWrapper, Telerik.Cms"), 
         Category("Behavior")] 
        public string SingleNewsPage 
        { 
            get 
            { 
                object obj = this.ViewState["SingleNewsPage"]; 
                if (obj != null
                    return (string)obj; 
                return String.Empty; 
            } 
            set 
            { 
                this.ViewState["SingleNewsPage"] = value; 
            } 
        } 
     
        /// <summary> 
        /// Gets or sets the url of the tagged news items 
        /// </summary> 
        [WebEditor("Telerik.Cms.Web.UI.UrlEditorWrapper, Telerik.Cms"), 
        Category("Behavior")] 
        public virtual string TaggedNewsUrl 
        { 
            get 
            { 
                object obj = this.ViewState["TaggedNewsUrl"]; 
                if (obj != null
                    return (string)obj; 
                ICmsUrlContext urlContext = CmsUrlContext.Current; 
                if (urlContext != null
                { 
                    return urlContext.Path; 
                } 
                return String.Empty; 
            } 
            set 
            { 
                this.ViewState["TaggedNewsUrl"] = value; 
            } 
        } 
     
        /// <summary> 
        /// Gets or sets the url of the categorized news items 
        /// </summary> 
        [WebEditor("Telerik.Cms.Web.UI.UrlEditorWrapper, Telerik.Cms"), 
        Category("Behavior")] 
        public virtual string CategoryNewsUrl 
        { 
            get 
            { 
                object obj = this.ViewState["CategoryNewsUrl"]; 
                if (obj != null
                    return (string)obj; 
                ICmsUrlContext urlContext = CmsUrlContext.Current; 
                if (urlContext != null
                { 
                    return urlContext.Path; 
                } 
                return String.Empty; 
            } 
            set 
            { 
                this.ViewState["CategoryNewsUrl"] = value; 
            } 
        } 
        #endregion 
     
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (this.manager == null
                this.manager = new NewsManager(this.ProviderName); 
     
            newsRotator.DataSource = manager.Content.GetContent(); 
            newsRotator.ItemDataBound += new Telerik.WebControls.RadRotator.RadRotatorItemEventHandler(newsRotator_ItemDataBound); 
            newsRotator.DataBind(); 
        } 
     
        void newsRotator_ItemDataBound(object sender, Telerik.WebControls.RadRotatorItemEventArgs e) 
        { 
            IContent cnt = (IContent)e.Item.DataItem; 
     
            //get Title 
            ITextControl title = (ITextControl)e.Item.FindControl("newsTitle"); 
            if (title != null
                title.Text = cnt.GetMetaData("Title").ToString(); 
     
            //get Thumbnail 
            string imgUrl = (string)cnt.GetMetaData("Thumbnail"); 
            Image img = (Image)e.Item.FindControl("thumbnail"); 
     
            if (img != null
            { 
                if (!String.IsNullOrEmpty(imgUrl)) 
                    img.ImageUrl = imgUrl; 
                else 
                    img.Visible = false
            } 
     
            if (String.IsNullOrEmpty(this.baseUrl) && !String.IsNullOrEmpty(this.SingleNewsPage)) 
            { 
                this.baseUrl = this.SingleNewsPage; 
                int idx = this.baseUrl.LastIndexOf('.'); 
                if (idx > -1) 
                    this.baseUrl = this.baseUrl.Substring(0, idx); 
                if (!this.baseUrl.EndsWith("/")) 
                    this.baseUrl += "/"
            } 
     
            if (!String.IsNullOrEmpty(this.baseUrl)) 
            { 
                string url = String.Concat(this.baseUrl, 
                                           UrlRewriterService.FormatURL(cnt, manager.SettingsElement)); 
                IUrlService svc = UrlServices.GetService("LanguageService"); 
     
                if (svc != null
                    url = svc.ResolveLanguageUrl(url); 
     
                HyperLink thumbnailLink = (HyperLink)e.Item.FindControl("thumbnailLink"); 
                if(thumbnailLink != null
                    thumbnailLink.NavigateUrl = url; 
     
                HyperLink titleLink = (HyperLink)e.Item.FindControl("titleLink"); 
                if(titleLink != null
                    titleLink.NavigateUrl = url; 
            } 
     
            //get Category 
            ITextControl category = (ITextControl)e.Item.FindControl("categoryName"); 
            if(category != null
                category.Text = cnt.GetMetaData("Category").ToString(); 
     
            HyperLink categoryNameLink = (HyperLink)e.Item.FindControl("categoryNameLink"); 
            ICategory ctg = this.manager.Content.GetCategory(cnt.GetMetaData("Category"as string); 
            if (categoryNameLink != null && ctg != null
                categoryNameLink.NavigateUrl = ResolveUrl(String.Concat(this.CategoryNewsUrl, "?CategoryID=", ctg.ID.ToString())); 
             
            //get all Tags 
            Repeater rptNewsTags = (Repeater)e.Item.FindControl("rptNewsTags"); 
            if (rptNewsTags != null
            { 
                IList newsTags = this.manager.Content.GetTags(cnt.ID); 
                if (newsTags.Count > 0) 
                { 
                    rptNewsTags.DataSource = newsTags; 
                    rptNewsTags.ItemDataBound += new RepeaterItemEventHandler(rptNewsTags_ItemDataBound); 
                    rptNewsTags.DataBind(); 
                } 
            } 
        } 
     
        void rptNewsTags_ItemDataBound(object sender, RepeaterItemEventArgs e) 
        { 
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
            { 
                ITag tag = (ITag)e.Item.DataItem; 
                HyperLink tagLink = (HyperLink)e.Item.FindControl("tagLink"); 
                if (tagLink != null
                { 
                    tagLink.Text = tag.TagName; 
                    tagLink.NavigateUrl = ResolveUrl(String.Concat(this.TaggedNewsUrl, "?TagID=", tag.ID.ToString())); 
                } 
            } 
        } 
        #region Private Members 
     
        private string providerName; 
        private NewsManager manager; 
        private string baseUrl; 
        #endregion 

    Hope this is helpful for you.

    Best wishes,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  9. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    22 Feb 2008
    Link to this post
    Hi,

    Many Thanks for extending, but how to be able to select for the news rotator one Categorie, for sample I have created many categories like sports, travels, holidays. How to select only the Sports to send to the Rotator. Regards
  10. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    22 Feb 2008
    Link to this post
    Hello Pierre,

    Here is a possible approach to implement such functionality:

    1. NewsRotator User Control should implement ICategorizedControl interface:
    public partial class UserControls_NewsRotator : System.Web.UI.UserControl, ICategorizedControl 

    2. Add SelectedCategories property:
          [Category("Data")] 
        [Description("Only the news items beloning to any of the listed categories will be displayed. If left blank, all news will be displayed.")] 
        [WebEditor("Telerik.Cms.Engine.WebControls.Categories.CategoriesSelector, Telerik.Cms.Engine")] 
        [TypeConverter("Telerik.Cms.Engine.WebControls.Categories.SelectedCategoriesConverter, Telerik.Cms.Engine")] 
        public virtual string[] SelectedCategories 
        { 
            get 
            { 
                return this.selectedCategories; 
            } 
            set 
            { 
                this.selectedCategories = value; 
            } 
        } 

    selectedCategories is a private variable of type string[].

    3. Filter current data source(manager.Content.GetContent()) by selected categories:
    private IList LoadData(string[] selectedCategories) 
        { 
            IList dataSource; 
            List<IMetaSearchInfo> filter = new List<IMetaSearchInfo>(); 
     
            if (selectedCategories != null
            { 
                if (selectedCategories.Length > 0) 
                { 
                    foreach (string category in selectedCategories) 
                        if (!String.IsNullOrEmpty(category)) 
                        { 
                            if (filter.Count == 0 || (filter.Count > 0 && filter[filter.Count - 1].Key != "Category")) 
                                filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Category", category, JoinType.Or)); 
                            else 
                                filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Category", category, JoinType.And)); 
                        } 
                } 
            } 
     
            dataSource = this.manager.Content.GetContent(filter.ToArray()); 
     
            return dataSource; 
        } 
     

    4. Use LoadData method as a data source of RadRotator:
     protected void Page_Load(object sender, EventArgs e) 
        { 
            ... 
            newsRotator.DataSource = this.LoadData(this.selectedCategories); 
            ... 
        } 

    Hope this helps.

    Regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  11. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    22 Feb 2008
    Link to this post
    Hi Pepi,

    Great works for all, many thanks. Could you explain more how to implement the ICategorizedControl in the NewsUserControl. What I need to add. Regards.
  12. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    22 Feb 2008
    Link to this post
    Hi Pepi,

    This is the rotator with the categories implemented but I have many problems with List<IMetaSearchInfo> and others errors. Could you help us more. Regards and good we. 
  13. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    25 Feb 2008
    Link to this post
    Hello Pierre,

    Please refer to your support ticket for a more detailed explanation how to fix this.

    Greetings,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  14. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    25 Feb 2008
    Link to this post
    Hi Pepi,

    Many Thanks. I have a dream. Could you imagine with us this rotator for new Module Images and Docs, select the library, select the categorie and show. We waiting for the new 3.2. Thanks for this great work. Regards
  15. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    25 Feb 2008
    Link to this post
    Hi Pierre,

    We are afraid it is not possible to provide an example for Images & Documents. It's a very time consuming task and you could implement the required functionality by yourself. Please use the provided NewsRotator.ascx User Control as an example how to achieve this.

    Also, please bear in mind that Categories will be removed from
    Images & Documents module for the official release of v3.2.

    In case you decide to start the implementation of the described scenario, we would gladly assist you with directions if you experience any problems.


    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  16. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    26 Feb 2009
    Link to this post

    I have implemented the user control as you suggested.  I've put the control on the site's homepage and it displays my most recent news item and when the link is clicked it navigates to the appropriate news page.

    However, if I go into the News Module and edit the Title of the displayed news article, the HyperLink on the Home page is never updated. 

    For example: 
         News Title: Latest News
        Hyperlink: 09-02-03/Latest_News.aspx

    Make the change to the title:
        News Title: Latest News2
        Hyperlink: 09-02-03/Latest_news.aspx

    When the user clicks on the link, the page is not found (because when you change the news title, it changes the page name.

    I've tracked it down to the following line of code...
    Coming into this snippet,
       cnt.GetMetaData("Title") = Latest News2

    if (!String.IsNullOrEmpty(this.baseUrl))
    {
        string url = String.Concat(this.baseUrl,
                   UrlRewriterService.FormatURL(cnt, this.manager.SettingsElement));
        IUrlService svc = UrlServices.GetService("LanguageService");
        if (svc != null)
        url = svc.ResolveLanguageUrl(url);
        Control lnk = e.Item.FindControl("newsLink");
        if (lnk is HyperLink)
            ((HyperLink)lnk).NavigateUrl = url;
    }

    Anyone have suggestions on how to fix this?

  17. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    26 Feb 2009
    Link to this post
    I was investigating a bit further and it seems that the Telerik.News.UrlRewriterService has a property called 'cache'.

    This cache has the old title of the News article, and I presume that the cached version is being returned when I call, FormatURL.

    I guess the question becomes, How do I invalidate the cache?
  18. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    26 Feb 2009
    Link to this post
    I was investigating a bit further and it seems that the Telerik.News.UrlRewriterService has a property called 'cache'.

    This cache has the old title of the News article, and I presume that the cached version is being returned when I call, FormatURL.

    I guess the question becomes, How do I invalidate the cache?
  19. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    03 Mar 2009
    Link to this post
    Hello michael,

    the class you are talking about is obsolete. Can you please let us know which version of Sitefinity you are using so that we can track the problem down.

    We are waiting for you response.

    Kind regards,
    Ivan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  20. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    03 Mar 2009
    Link to this post
    We are using version 3.5 of site finity.  If that class is obsolete, can you indicate a replacement class and provide some sample code on how to use it?
  21. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    06 Mar 2009
    Link to this post
    I'm wondering if you have any progress to report on this issue?
  22. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    07 Mar 2009
    Link to this post
    Hello michael,

    Here is an example how to get the url to a single content item:

    private string GetItemUrl(IContent contentItem, string singleItemUrl) 
        { 
            string ret = String.Empty; 
            string url = singleItemUrl; 
     
            if (!String.IsNullOrEmpty(singleItemUrl)) 
            { 
                throw new Exception("SingleItemUrl property is not set!"); 
            } 
            
            if (!String.IsNullOrEmpty(contentItem.Url)) 
            { 
                string itemUrl = String.Concat(contentItem.Url, Manager.Provider.ContentExtension); 
     
                if (String.IsNullOrEmpty(Context.Request.QueryString["ReturnURL"])) 
                { 
                    ret = String.Concat("?ReturnURL=", Context.Server.UrlEncode(Context.Request.RawUrl)); 
                } 
                else 
                { 
                    ret = String.Concat("?ReturnURL=", Context.Server.UrlEncode(Context.Request.QueryString["ReturnURL"])); 
                } 
                
                if (!itemUrl.StartsWith("~")) 
                { 
                    int idx = url.LastIndexOf('.'); 
                    if (idx != -1) 
                    { 
                        url = url.Substring(0, idx); 
                    } 
                    else 
                    { 
                        idx = url.IndexOf('?'); 
                        if (idx != -1) 
                            url = url.Substring(0, idx); 
                    } 
     
                    itemUrl = String.Concat(VirtualPathUtility.RemoveTrailingSlash(url), itemUrl); 
                } 
                url = String.Concat(itemUrl, ret); 
            } 
     
            IUrlService svc = UrlServices.GetLanguageService(); 
            if (svc != null
                url = svc.ResolveLanguageUrl(url); 
     
            return url; 
        } 

    Then, you need just to call GetItemUrl method:

    Control lnk = e.Item.FindControl("newsLink"); 
    if (lnk is HyperLink) 
        ((HyperLink)lnk).NavigateUrl = this.GetItemUrl(cnt, this.SingleItemUrl); 

    Note that on the single item page you should have an instance of the NewsView control and its BehaviorMode property should be set to Detail.

    Do let us know if you still experience any problems.

    Kind regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  23. michael
    michael avatar
    20 posts
    Registered:
    09 Jan 2009
    10 Mar 2009
    Link to this post
    I have a few questions about your response.

    1) You said...
    "Note that on the single item page you should have an instance of the NewsView control and its BehaviorMode property should be set to Detail."

    However, I don't have a single item page nor a News View on my page.  My control is identical to the one contained within the Rar file found earlier in this thread.  Does this mean that the code will only work if I am using a News View in my control?

    2) In the code, there are two references that I need clarification on (they might be related to the fact that I don't have a NewsView in my control.

    "string itemUrl = String.Concat(contentItem.Url, Manager.Provider.ContentExtension);"
    "((HyperLink)lnk).NavigateUrl = this.GetItemUrl(cnt, this.SingleItemUrl);"

    I don't have a 'Manager'.  What type of Manager is needed?  I have a NewsManager as part of my control but it doesn't have a reference to a Provider property.

    The control does not have a 'SingleItemUrl'.  Where would I get that from?

    --michael
  24. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    16 Mar 2009
    Link to this post
    Hello Michael,

    The NewsList control/class is obsolete as you thought in the previous post. That is why we are showing you an example with NewsView. NewsList itself is removed completely in the latest release.
    Please take a look at these lines:
     ContentManager manager = new ContentManager("News"); 
     //manager.Provider.ContentExtension 
     NewsView c = new NewsView(); 
     //c.SingleItemUrl 

    I hope this helps.

    Kind regards,
    Georgi
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
24 posts, 0 answered