You Can Either dynamically add it via a Generic HTML control:
using System.Web.UI.HtmlControls;
protected override void OnInit(EventArgs e)
{
// Define an Literal control.
HtmlGenericControl css = new HtmlGenericControl();
css.TagName = "style";
css.Attributes.Add("type", "text/css");
string imageURL = string.Empty;
//Logic to determin imageURL goes here
//Update Tag
css.InnerHtml = @"body{background-image: url(" + imageURL + ");}";
// Add the Tag to the Head section of the page.
Page.Header.Controls.Add(css);
base.OnInit(e); }
The other option is to have a publically exposed property from the code-behind
E.g.
public string backgroundImage = "defaultImage.png";
Update this in page init or onload events.
And reference it in the aspx file either in the head:
<style type="text/css">
body
{
background-image:url(<%=backgroundImage%>);
}
</style>
or as an attribute of the body tag
<body style="background-image: url(<%= backgroundImage %>)">
Either of these should be able to help you out.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…