More in this section

Forums / Developing with Sitefinity / Showing Thumbnail on SingleNews

Showing Thumbnail on SingleNews

25 posts, 0 answered
  1. Kwinten Volckaert
    Kwinten Volckaert avatar
    41 posts
    Registered:
    01 Mar 2005
    18 Oct 2007
    Link to this post
    How does one show the thumbnail on a SingleNews-page...
    What do I need to put in the ImageUrl tag?

    <asp:Image ID="Thumbnail" runat="server" />

  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    18 Oct 2007
    Link to this post
    Hello Kwinten,

    If I understand correctly you want to display Thumbnail in the SingleNews. To achieve this it is not enough to modify SingleNews template. You need to extend the SingleNews control or make your own implementation of this control.

    In the attachment you could find a simple example how to extend SingleNews.

    Let us know if you need any further assistance.

    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Kwinten Volckaert
    Kwinten Volckaert avatar
    41 posts
    Registered:
    01 Mar 2005
    22 Oct 2007
    Link to this post
    Well I guess I'm going to need further assistance.
    I put the code to my user control, but I'm guessing that wasn't the intention. I want to extend the SingleNews control, but how do I do this, and how do I make my usercontrol point to the new class?

    Now I'm getting 

     

    Server Error in '/' Application.

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0246: The type or namespace name 'SingleNews' could not be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 9:  /// Summary description for Sitefinity_ControlTemplates_Interviews_SingleNews
    Line 10: /// </summary>
    Line 11: public partial class Sitefinity_ControlTemplates_Interviews_SingleNews : System.Web.UI.UserControl, SingleNews
    Line 12: {
    Line 13:     #region Event Handlers
  4. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    22 Oct 2007
    Link to this post
    Hi Kwinten,

    In this case you can't use User Control because C# does not support multiple implementation inheritance. A class cannot be derived from more than one class i.e your class can't inherit UserControl and SingleNews classes at the same time. However, a class can be derived from multiple interfaces.

    To extend SingleNews control, you need to create a custom control that inherits SingleNews class as in the sent example. After that, you could upload the control manually by modifying web.config. To achieve this follow the instructions below:

    1.Open the web.config file and add the following in the <toolboxControls>  section:
    <add name="Custom Control" section="Custom Controls" type="Namespace.ClassName, AssemblyName" /> 

    2.Upload your assembly in the bin folder of your project.



    In this way your control will be automatically inserted into the Toolbox.

    Let us know how it goes.

    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Kwinten Volckaert
    Kwinten Volckaert avatar
    41 posts
    Registered:
    01 Mar 2005
    22 Oct 2007
    Link to this post
    I made a new project and put the class file there but I can't compile it. I'm guessing I'm missing references. I get an error on the Engine part of Telerik.CMS.Engine and an error on the SingleNews
    I added the following references allready :
    Telerik.Framework
    Telerik.CMS.Web.UI
    Telerik.Security
  6. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    22 Oct 2007
    Link to this post
    Hi Kwinten,

    Have a look at the attached screenshot: it shows all necessary references that should be added to your project.

    Also, here is a minor improvement of the code from the previous post:

    using System; 
    using System.Collections.Generic; 
    using System.Text; 
    using Telerik.Cms.Engine; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using Telerik.News.WebControls; 
     
    namespace Kwinten 
        public class ExtSingleNews : SingleNews 
        { 
            protected override void CreateChildControls() 
            { 
                base.CreateChildControls(); 
     
                if (base.ArticleID == Guid.Empty) 
                    return
     
                IContent cnt = base.NewsMngr.Content.GetContent(base.ArticleID); 
     
                foreach (IMetaInfo info in base.newsManger.Content.MetaKeys.Values) 
                { 
                    Control ctrl = this.container.GetControl(info.Key); 
                    if (ctrl is Image) 
                    { 
                        object metaData = cnt.GetMetaData(info.Key); 
                        Image img = ctrl as Image; 
                         
                        if (metaData != null
                            img.ImageUrl = cnt.GetMetaData(info.Key).ToString(); 
                    } 
                } 
            } 
        } 

    Hope this helps.

    Greetings,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. Tim
    Tim avatar
    156 posts
    Registered:
    23 Sep 2007
    22 Oct 2007
    Link to this post

    Hi Pepi,

    I wanted to add Thumbnail into single news too.  I created a new custom control project and copy and paste your code. I complied without any problem. Then uploaded .dll file into bin folder and edit web.config file. But for some reason, the thumbnail doesn't show up at all.

    Any idea why...
    Thanks
    Tim

  8. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    23 Oct 2007
    Link to this post
    Hi Tim,

    You should modify the SingleNews.ascx template also i. e. you should add an Image control that will display the Thumbnail on the SingleNews control. The template that should be changed is located in ~/Sitefinity/ControlTemplates/News/ folder.

    Hope this helps.

    All the best,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  9. Tim
    Tim avatar
    156 posts
    Registered:
    23 Sep 2007
    23 Oct 2007
    Link to this post
    Thanks Pepi!

    It works now.

    Tim
  10. Tim
    Tim avatar
    156 posts
    Registered:
    23 Sep 2007
    24 Oct 2007
    Link to this post

    Sitefinity Team,

    after I modified SingleNews.ascx template, it works fine for the news which has thumbnail. But it shows can't display image sign on the page when the news doesn't have thumbnail. It kind of looks ugly on the page and confuse the end user.

    Please let me know if there is any way to fix it.
    Thanks
    Tim

  11. Kwinten Volckaert
    Kwinten Volckaert avatar
    41 posts
    Registered:
    01 Mar 2005
    24 Oct 2007
    Link to this post
    You should do something like this :

    protected bool getVisible(object oImage)

    {

        protected bool getVisible(object oImage)  
        {  
            try  
            {  
                string sImage = oImage.ToString();  
                if (sImage.Trim() == "")  
                    return false;  
                return true;  
            }  
            catch  
            {  
                return false;  
            }  
        } 

    and

            <asp:Image ID="Logo" ImageUrl='<%#DataBinder.Eval(Container.DataItem, "Logo")%>' 
                runat="server" Width="40" Style='float: left; margin: 3px 5px 3px 5px' Visible='<%#getVisible(DataBinder.Eval(Container.DataItem, "Logo"))%>' /> 
     


    It should work :)
  12. Tim
    Tim avatar
    156 posts
    Registered:
    23 Sep 2007
    24 Oct 2007
    Link to this post

    Hi Kwinten,

     Could you please give more details how to add protected bool getVisible(object oImage) function and where to add it?


    Thanks in advance

    Tim

  13. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    24 Oct 2007
    Link to this post
    Hello Tim,

    You need to handle this in ExtSingleNews class. First of all, you should make a check if cnt.GetMetaData(info.Key).ToString() is an empty string. After that there are two possible solutions if a given news item doesn't have Thumbnail:

    1. Make Image control invisible - img.Visible = false;
    2. Set the ImageUrl property of Image control to some default image - img.ImageUrl = "~/Images/NoThumbnail.jpg";

    Hope this helps.

    All the best,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  14. Tim
    Tim avatar
    156 posts
    Registered:
    23 Sep 2007
    24 Oct 2007
    Link to this post
    It works!

    Thanks  a lot
    Tim
  15. Kwinten Volckaert
    Kwinten Volckaert avatar
    41 posts
    Registered:
    01 Mar 2005
    16 Apr 2008
    Link to this post
    When I use the code that I made to make this work in SiteFinity 3.2 SP1 I get the follwoing error when building the project : 

    Could not load type 'Telerik.Utilities.CodeBenchmarkTextFileProvider' from assembly 'Telerik.Framework'.
  16. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    17 Apr 2008
    Link to this post
    Hi Kwinten Volckaert,

    Could you check the version of the Telerik.Framework assembly?

    We suggest you to remove all your references to this assembly (in the custom code that we have provided you) and then add the references again. It seems that for some reason you are accessing an old assembly with the new project.

    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  17. Markus66
    Markus66 avatar
    6 posts
    Registered:
    28 Dec 2006
    15 May 2008
    Link to this post
    Hello,

    I'm trying to add a thumbnail like you discussed in this post, but when I add the Image control to the SingleNews.ascx file I get this error:

     

    Server Error in '/RunggaldierWebsite' Application.

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30456: 'DataItem' is not a member of 'System.Web.UI.Control'.

    Source Error:

    Line 4:      <h2 class="singlenews"><asp:Literal ID="Title" runat="server" />&nbsp;</h2>
    Line 5:  
    Line 6:  <asp:Image ID="Thumbnail" ImageUrl='<%#DataBinder.Eval(Container.DataItem, "Thumbnail")%>' runat="server" />
    Line 7:  
    

    What am I doing wrong?
  18. Markus66
    Markus66 avatar
    6 posts
    Registered:
    28 Dec 2006
    16 May 2008
    Link to this post
    Solved, sorry, I had only to remove the complete imageUrl Tag because the error was there.
  19. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    16 May 2008
    Link to this post
    Hello Markus,

    We are glad that you were able to solve the problem yourself and apologize that we could not help you right away.
    Don't hesitate to contact us if you have other questions.


    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  20. Andreas
    Andreas avatar
    49 posts
    Registered:
    29 Dec 2007
    20 Jan 2009
    Link to this post
    How do we go about this now that we're using ListPageDetails.ascx instead?

    //Andreas
  21. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    22 Jan 2009
    Link to this post
    Hi Andreas,

    Please try to add the following:

    <h1><asp:Literal ID="Title" runat="server"></asp:Literal></h1>   
    <h3> 
    <asp:PlaceHolder ID="ThumbnailHolder" runat="server" Visible="true">  
    <asp:Image ID="Thumbnail" runat="server" Width="240" Height="180" CssClass="img-right" ></asp:Image>   
    </asp:PlaceHolder>   
    <asp:Literal ID="Summary" runat="server"></asp:Literal>   
    </h3>   
    <p><asp:Literal ID="content" runat="server"></asp:Literal></p>  

    Let us know about the results.

    Kind regards,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  22. Andreas
    Andreas avatar
    49 posts
    Registered:
    29 Dec 2007
    23 Jan 2009
    Link to this post
    Works like a charm! Thanks! :)

    //Andreas
  23. David Meyer
    David Meyer avatar
    13 posts
    Registered:
    29 Oct 2009
    25 Nov 2009
    Link to this post
    Im developing a custom module (extending Generic Content, based on the Products sample code) and I'm customizing the public facing ListPageMaster.ascx. I want to add a thumbail image to the public page. I've got the admin side working.  I've tried the following, as suggested in the previous posts and the image is rendered without a src.

    <asp:PlaceHolder ID="ThumbnailHolder" runat="server" Visible="true">     
    <asp:Image ID="Thumbnail" runat="server" Width="240" Height="180" CssClass="img-right" ></asp:Image>      
    </asp:PlaceHolder>     
     

    I then added an override to SetItemMetadata in my PublicView.cs file as in this post to set the ImageURL
    http://www.sitefinity.com/support/forums/sitefinity-3-x/developing-with-sitefinity/question-regarding-public-view-control-for-generic-content-module.aspx  like so:

    protected override void SetItemMetadata(System.Web.UI.Control itemContainer, Telerik.Cms.Engine.IContent contentItem)  
    {  
        base.SetItemMetadata(itemContainer, contentItem);  
     
        Image thumb = itemContainer.FindControl("Thumbnail") as Image;  
        if (thumb != null)  
        {  
            String thumbReference = contentItem.GetMetaData("Thumbnail").ToString();  
     
            if (String.IsNullOrEmpty(thumbReference))  
            {  
                thumb.Visible = false;  
            }  
            else  
            {              
                thumb.ImageUrl = thumbReference;  
                thumb.Visible = true;  
            }  
        }  

    But the output, particularly the src of the image is not what I expect

     
    <img id="ctl00_brandImage_RelatedLinksPublicView1_ctl00_ctl00_repeater_ctl01_Thumbnail" src="CustomControls/RelatedLinks/%5BLibraries%5D4c9030f0-daa3-4205-81a1-2fed7d18a5c1" style="border-width:0px;" />    
     
     
     

    Not sure what is happening here?
  24. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    25 Nov 2009
    Link to this post
    Hi David Meyer,

    Thank you for using our services.

    The difference between your custom module and the News Module is that the News Module has built in methods for handling references to content items such as images from Images & Documents. You are getting the thumbnail in the [ProviderName]Guid format. Now you should parse this string to get the content item and get its url. Please take a look at Resolving the url of dynamic links to see how to achieve this.

    Greetings,
    Radoslav Georgiev
    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.
  25. David Meyer
    David Meyer avatar
    13 posts
    Registered:
    29 Oct 2009
    25 Nov 2009
    Link to this post
    That put me on the right path. Actually I used the GetURL method from this thread like this and it works

    thumb.ImageUrl = GetUrl(thumbReference)
Register for webinar
25 posts, 0 answered