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.jpgHere 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" />)%>');
}
<开发者_如何学JAVA;/style>
</asp:content>
Anyone know any solution? Thanks in advance.
If it's just a plain textstring then you can do the following:
<%@ Master Language="C#" MasterPageFile="/masterpages/Master.master" AutoEventWireup="true" %>
<%@ Import Namespace="umbraco" %>
<%@ Import Namespace="umbraco.presentation" %>
<%@ Import Namespace="umbraco.presentation.nodeFactory" %>
<asp:content ContentPlaceHolderId="cphHead" runat="server">
<style type="text/css">
#content {
background: url('<%=VirtualPathUtility.ToAbsolute(Node.GetCurrent().GetProperty("background").Value)%>');
}
</style>
</asp:content>
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
精彩评论