More in this section
Forums / Bugs & Issues / Can not load images from custom module to custom control

Can not load images from custom module to custom control

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
4 posts, 1 answered
  1. Ashfaq
    Ashfaq avatar
    5 posts
    21 Aug 2013
    12 Sep 2013
    Link to this post
    Hello there,
    i have created custom module for news listing, and also custom control to show news in tabs,
    everything is working fine except images, i am not able to load images at all i have tried alot of changes, but none of them worked yet here is my repeater code

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CustomTabs.ascx.cs" Inherits="Custom_Widgets_CustomTabs" %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Fields" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
    <!-- News Tab Start -->
        <div id="tabs-1" aria-labelledby="ui-id-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom" role="tabpanel" aria-expanded="true" aria-hidden="false">
            <asp:Repeater ID="rpt_news" runat="server" OnItemDataBound="rpt_news_ItemDataBound">
                <div class="mid-left">
                     <asp:Image ID="NewsImage" runat="server"/>
                     <h1><%# Eval("Title")%></h1>
                    <span class="date"><sf:FieldListView ID="PublicationDate" runat="server" Format="{PublicationDate.ToLocal():MMM d, yyyy, HH:mm tt}"/></span>
                    <span class="des">
                      <asp:Label ID="lbldescription" runat="server" Text='<%# (Eval("content").ToString().Length > 150 ? Eval("content").ToString().Substring(0,150)+"..." : Eval("content")) %>'></asp:Label>
       <!-- News Tab End -->

    and here is codebehind

    protected void Page_Load(object sender, EventArgs e)
           rpt_news.DataSource = GetLastsNews();
           rpt_videos.DataSource = GetLatestVideos();
       public IQueryable<DynamicContent> GetLastsNews()
           DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
           Type newsListingType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.NewsList.NewsListing");
           var myCollection = dynamicModuleManager.GetDataItems(newsListingType)
               .Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Visible == true);
           return myCollection.Take(3).Skip(0).OrderBy(o => o.Id);
    public void rpt_news_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
           if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
               //// this one is giving erro unable to cast
               Telerik.Sitefinity.Libraries.Model.Image newsImage = (Telerik.Sitefinity.Libraries.Model.Image)TypeDescriptor.GetProperties(e.Item.DataItem)["NewsImage"].GetValue(e.Item.DataItem);
               var imageControl = (Image)e.Item.FindControl("NewsImage");
               if (imageControl != null)
                   /// this one is showing error Object reference not set to an instance of an object.
                   var image = e.Item.DataItem as Telerik.Sitefinity.Libraries.Model.Image;
                   imageControl.ImageUrl = image.MediaUrl;
                   // i have just added 2 times this to show you that i have tried both but non of them working
                   imageControl.ImageUrl = newsImage.MediaUrl;

    i have also tried to convert telerik content link to Image url with this one code but there is no method found at (showcase.GetValue("Screenshot");) GetValue is not exists

    protected string GetImageUrl(object item)
        var retval = string.Empty;
        // ensure correct item type
        var showcase = item as DynamicContent;
        if (showcase == null) return retval;
        // retrieve the Screenshot value and extract the first (and only) item
        var contentLinks = (ContentLink[])showcase.GetValue("Screenshot");
        ContentLink imageContentLink = contentLinks.FirstOrDefault();
        // retrieve the image using the extracted items Id
        LibrariesManager libraryManager = LibrariesManager.GetManager();
        var image = libraryManager.GetImage(imageContentLink.ChildItemId);
        if (image == null) return retval;
        // return the image url to the template
        retval = image.Url;
        return retval;

    also tried to use sf sf:ImageAssetsField 

    <sf:ImageAssetsField runat="server" DataFieldName="thumb" IsThumbnail="False" DisplayMode="read"/>

    but its also showing empty image why anything doesn't work ?
    can anyone help please ? i can not find any way to do it
  2. Ashfaq
    Ashfaq avatar
    5 posts
    21 Aug 2013
    13 Sep 2013 in reply to Ashfaq
    Link to this post
    Thanks to all i have resolved my issue my self as i do always :)
  3. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    26 Mar 2015
    17 Sep 2013
    Link to this post
    Hi Ashfaq,

    Can you please share with us the solution to your problem so if anyone encounters it they have a reliable resource available. In my view the best way for you to upload images to a custom control is with Sitefinity's HtmlField. It allows you the same functionality that our content block does. All you need to do to use it is create a widget with designer and include the HtmlField in the designer. I have attached a simple designer that allows you to use the HtmlField as an image selector.

    Ivan D. Dimitrov
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Ashfaq
    Ashfaq avatar
    4 posts
    22 Aug 2013
    06 Dec 2013 in reply to Ivan D. Dimitrov
    Link to this post
    Hello i had solved that issue via creating a function in code behind file at our custom control, and called that method inside control.ascx file where i have added a repeater & image control field to show the image here is the solution with example in my site
    Get Images in custom control from Custom module image asset field
4 posts, 1 answered