asp.net - Setting media URLs in Sitecore -
there few similar questions here , here have not been able resolve problem.
i want have 'download plans' link download image in sitecore 6.4.1. have set images backgrounds , such, linking href has proven difficult.
in ascx control set sublayout, front-end code looms this:
<a class="btn btn-default" id="download_plans" runat="server" clientidmode="static"> download plans </a> and 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 of controls have same code, except instead of adding href attribute, added value style using code below. 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, field called "floor plan image" - correct string use when retrieving element (it "image" in other control, generic)? nothing being added element @ all.
any suggestions?
you have same snippet of code in 1 of controls. if it's not working there, real reason can think of is; other control hosted on page of different template type - 1 not include floor plan image.
check control hosted on page template expect.
ideally, should try not relying on sitecore.context.item in components; reason , many more.
Comments
Post a Comment