There are a few similar questions here and here but I have not been able to resolve my problem.
I want to have a 'Download Plans' link that will download an image in Sitecore 6.4.1. I have successfully set images as backgrounds and such, but linking as an href has proven difficult.
In my ASCX control which is set as a sublayout, the front-end code looms like this:
<a class="btn btn-default" id="download_plans" runat="server" ClientIDMode="Static">
Download Plans
</a>
And my code-behind has this:
private void Page_Load(object sender, EventArgs e)
{
if (((Sitecore.Data.Fields.ImageField)Sitecore.Context.Item.Fields["Floor Plan Image"]).MediaItem != null)
{
var url = Sitecore.StringUtil.EnsurePrefix('/', MediaManager.GetMediaUrl(((Sitecore.Data.Fields.ImageField)Sitecore.Context.Item.Fields["Floor Plan Image"]).MediaItem));
download_plans.HRef = url;
}
}
In another of my controls I have the same code, except instead of adding the HRef attribute, I added the value as a style using the code below. This works fine
download_plans.Attributes.Add("style", string.Format("background-position:right bottom; background-image:url(\"{0}\"); background-repeat:no-repeat; background-size:contain", url));
In Sitecore, the field is called "Floor Plan Image" - is this the correct string to use when retrieving the element (It is "Image" in my other control, which is very generic)? Currently nothing is being added to the element at all.
Any suggestions?
HRefis executed at all?"Floor Plan Image"is a correct string for the field name. Just remember to useName(notDisplay Name). - Marek Musielak<asp:HyperLink CssClass="btn btn-default" ID="download_plans" runat="server" ClientIDMode="Static">and set theNavigateUrlinstead - jammykam