Can not load images from custom module to custom control

Posted by Community Admin on 04-Aug-2018 15:45

Can not load images from custom module to custom control

All Replies

Posted by Community Admin on 12-Sep-2013 00:00

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

Posted by Community Admin on 13-Sep-2013 00:00

Thanks to all i have resolved my issue my self as i do always :)

Posted by Community Admin on 17-Sep-2013 00:00

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

Posted by Community Admin on 06-Dec-2013 00:00

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

This thread is closed