I know you can’t put a control inside a C# function like this
<%= VirtualPathUtility.ToAbsolute(<umbraco:Item field="background" runat="server" />) %>
but I am wondering if you can pass the value from a control to a C# function.
umbraco:Item above outputs something like ~/media/bg1.jpg
Here is what I am trying to do:
<%@ Master Language="C#" MasterPageFile="/masterpages/Master.master" AutoEventWireup="true" %>
<asp:content ContentPlaceHolderId="cphHead" runat="server">
<style type="text/css">
#content {
background: url('<%=VirtualPathUtility.ToAbsolute(<umbraco:Item field="background" runat="server" />)%>');
}
</style>
</asp:content>
Anyone know any solution? Thanks in advance.
If it’s just a plain textstring then you can do the following:
However, if the “background” property is a media picker then you need a little more help than just that, which will involve the umbraco.cms.businesslogic.media namespace. I suggest you check out the libraries with Reflector, or the source code repository on Codeplex to find out the classes you should be using and how to subsequently populate your property.
HTH,
Benjamin