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

Forums / Developing with Sitefinity / Widget Template - Modifying output of AssetsField control

Widget Template - Modifying output of AssetsField control

3 posts, 0 answered
  1. Nick
    Nick avatar
    18 posts
    Registered:
    19 Jul 2012
    14 Jun 2012
    Link to this post
    I'm displaying an AssetsField control on the details-widget template for a custom module (projects). it looks like this

    <sf:AssetsField ID="download" runat="server" DataFieldName="Download" />

    By default, the link that is displayed has link text matching the file-name of the document. What I want instead is for the link to say "Download Project Info Sheet" instead of "filename.pdf". Is this possible with the AssetsField control? 
  2. Paul
    Paul avatar
    6 posts
    Registered:
    04 Sep 2012
    28 Nov 2012
    Link to this post
    What is the resolution to this?  I haven't yet found documentation for how to accomplish exactly what the original poster was doing.
  3. Pavel Benov
    Pavel Benov avatar
    341 posts
    Registered:
    14 Mar 2016
    30 Nov 2012
    Link to this post
    Hi guys,

    The default AssetsField control does not provide such functionality, so you will need to create a custom one.

    What you need to do is to create a class, inherit from AssetsField and replace the template of the control with a custom one. Here is what your code should look like:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Sitefinity.Web.UI.Fields;
     
    namespace SitefinityWebApp
    {
        public class CustomAssets : AssetsField
        {
            protected override string ScriptDescriptorTypeName
            {
                get
                {
                    return typeof(AssetsField).FullName;
                }
            }
     
            public override string LayoutTemplatePath
            {
                get
                {
                    return layoutTemplatePath;
                }
                //set
                //{
                //    base.LayoutTemplatePath = value;
                //}
            }
     
            public string layoutTemplatePath = "~/AssetsFieldCustomTemplate.ascx";
        }
    }

    When you're using the document mode of the AssetsField control, the link to your document is displayed in the template of the AssetsField by a documentLink control (which is a Sitefinity control):

    <sf:DocumentLink id="documentLink" runat="server" />

    You can get to it with code behind and modify it from there. 

    You can find the AssetsField's default template attached to this response or in our SDK by navigating to Content->Resources->WidgetTemplates.zip.

    Kind regards,
    Pavel Benov
    the Telerik team
    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
3 posts, 0 answered