More in this section

Forums / Developing with Sitefinity / Custom News Control

Custom News Control

5 posts, 0 answered
  1. pbland
    pbland avatar
    1 posts
    Registered:
    09 May 2008
    16 Jun 2008
    Link to this post
    Hi all.

    I am currently trying to develop a Custom News Control that will be able to retreive news articles from the CMS based on a filter-expression etc & display the details such as Title/Summary etc. I have successfully managed to modify the NewsList ControlTemplate to my purposes but I need the NewsList as is for use on other pages. I would be grateful if someone could explain how I might go about adding another NewsList ControlTemplate or how to go about retreiving News details from the CMS that I can use with a custom control. I have managed to find articles/documentation on how to extend the singleNews control but could find nothing about how to pull News Article info.

    Within the NewsList ControlTemplate databinding is acheived by this:


    <
    a ID="newsLink"><%#DataBinder.Eval(Container.DataItem, "Title")%></a>

    but I cant seem to work out how to make this work in a custom control as this only seems to work within the existing ControlTemplate. Does this have anything to do with the NewsManager & Provider??

    Many Thanks in advance for any help.

  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    17 Jun 2008
    Link to this post
    Hello pbland,

    If I understand correctly, you want to create a custom NewsList control and set your own template for it. I would recommend you implement a control that derives from the NewsList base class. In this case you need just to override TemplateUrl property to achieve the required functionality:

    using Telerik.News.WebControls; 
    using Telerik.News; 
     
    /// <summary> 
    /// Summary description for CustomPollBox 
    /// </summary> 
    namespace MyNamespace 
        public class CustomNewsList : NewsList 
        { 
            public CustomNewsList() 
            { 
            } 
     
            public override string TemplateUrl 
            { 
                get 
                { 
                    return "~/Sitefinity/ControlTemplates/News/CustomNewsList.ascx"; 
                } 
                set 
                { 
                    base.TemplateUrl = value; 
                } 
            } 
     
            protected override void CreateChildControls() 
            { 
                base.CreateChildControls()
            } 
        } 
     

    Please note that you need to declare you control in the project web.config file to display it in the "Add Controls" toolbox:

    <toolboxControls> 
            ... 
            <add name="Custom News List" section="News" type="MyNamespace.CustomNewsList, App_Code" /> 
            ... 

    Please describe in details if there is some misunderstanding.

    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. nogatek
    nogatek avatar
    35 posts
    Registered:
    23 Apr 2008
    16 Jul 2008
    Link to this post
    Hi there, I'm trying to implement this solution but am a bit stuck.

    What would the actual .ascx page look like?

    Thanks, Mark
  4. nogatek
    nogatek avatar
    35 posts
    Registered:
    23 Apr 2008
    16 Jul 2008
    Link to this post
    Sorry, didn't realize I just had to copy over and rename the existing .asxm file!

    All sorted.

    Thanks, Mark
  5. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    16 Jul 2008
    Link to this post
    Hello Mark,

    ASP.NET templates describe the static HTML, controls, and script to render within the public controls and give you the opportunity to customize the control user interface. They contain both ASP.NET server controls and plain HTML elements that make up the layout of the control. So to create your own template for the NewsList control, you can copy the original one (~/Sitefinity/ControlTemplates/News/NewsList.ascx) and rename it. Also, you need to copy the corresponding .resx file that is located in ~/Sitefinity/ControlTemplates/News/App_LocalResources folder. After that, you should change the CSS styles of the new template in order to modify the appearance of the NewsList.

    Do let us know how it goes.

    All the best,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
5 posts, 0 answered