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

Forums / Developing with Sitefinity / sf:ImageField doesn't display the image

sf:ImageField doesn't display the image

5 posts, 1 answered
  1. Osman
    Osman avatar
    22 posts
    Registered:
    04 Oct 2010
    10 Jul 2013
    Link to this post
    I created a custom module using Module builder.
    There is an image field "Thumbnail", I like to display in the list view. Since it is an optional field, and in case of its absence, I need to display a default image.

    When I use ImageField with DefaultSrc pointing to the default image, only image I see in the list view is the default image. Even the content with thumbnail field populated, displays the default image instead:

    <sf:ImageField runat="server"
      DataFieldName="Thumbnail"
      DataFieldType="Telerik.Sitefinity.Model.ContentLinks.ContentLink"
      DisplayMode="Read"
      DefaultSrc="~/images/default-source/grants/thumbnails/default.png" />


    What am I missing here? Does "DefaultSrc" attribute have a different purpose or use case than I am trying to accomplish?

    Thanks,

    Osman
  2. Jonathan
    Jonathan avatar
    119 posts
    Registered:
    19 Dec 2012
    11 Jul 2013 in reply to Osman
    Link to this post
    Not sure what the DefaultSrc should be doing but maybe trying this sf:conditional statement.  This is from the forum list but you can change the parameters to fit your needs.

    <sf:Conditional If='<%# (DateTime)Eval("UserRegistrationDate") > DateTime.MinValue.ToUniversalTime() %>' runat="server">
                       <Then>
                           <div class="sfforumUserPostsInfo">
                               <%# Eval("UserPostCount") %> <asp:Literal Text="<%$ Resources:ForumsResources, Posts %>" runat="server" /><br />
                        
                               <asp:Literal Text="<%$ Resources:ForumsResources, RegisteredTitleCase %>" runat="server" />:<br />
                               <%# ((DateTime)Eval("UserRegistrationDate")).ToString("dd MMM yyyy") %>
                           </div>
                       </Then>
                   </sf:Conditional>
    Answered
  3. Osman
    Osman avatar
    22 posts
    Registered:
    04 Oct 2010
    12 Jul 2013 in reply to Jonathan
    Link to this post
    Thanks Jonathan for your suggestion.
    I didn't know about sf:Conditional, which will be very handy for sure.

    I still would like to know how sf:ImageField's DefaultSrc suppose to work though. Anyone?
  4. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    15 Jul 2013
    Link to this post
    Hi guys,

     In the js file of the ImageField we make the following check:

    if (this._imageElement.src == "") {
        if (this._defaultSrc) {
            this._imageElement.src = this._defaultSrc;
        }
    }
    In such case, the defaultSrc should only get applied when the ImageElement doesn't have a src value.

    Regards,
    Jen Peleva
    Telerik
    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
  5. Osman
    Osman avatar
    22 posts
    Registered:
    04 Oct 2010
    15 Jul 2013 in reply to Jen Peleva
    Link to this post
    Hi Jen,

    I am not really clear this check is only done in client-side JavaScript.

    With this control, my assumption was the default image would be displayed if Thumbnail image is not defined.
    However, if I use the <sf:ImageField component as described above; in a user control/widget, I only see the default image, even when Thumbnail is defined.

    So Jen, I appreciate if you could clarify the usage scenarios of <sf:ImageField /> and the DefaultSrc attribute.

    Thanks,
    Osman 
5 posts, 1 answered