One way you can do it is have a property like this (a method will also work):
protected string BodyBackgroundImageUrl
{
get
{
// I just chose random pic
return "http://www.google.com/images/logos/ps_logo2.png";
}
}
You don't have to set the value like this, you can fill it later from page Init
event.
Then in the body you can do something like:
<body style='background:url(<%= BodyBackgroundImageUrl %>) no-repeat;'>
The no-repeat is just to show you can write whatever you want all around.
Of course you can even have more control, and different ways of things:
public string GetBodyStyle()
{
// Get the picture somehow dynamically
string bodyBackgroundImageUrl = GetBodyBackgroundImageUrl();
// You can use StringBuilder or so, not the main point
var styles = "";
styles += string.Format("background:url({0}) no-repeat;", bodyBackgroundImageUrl);
// ... Add some extra styles if you want ...
return styles;
}
And then your Body tag will look like:
<body style='<%= GetBodyStyle() %>'>
...
Also, you can always use a hidden field that you assign the value from the page, and then in browser set the background URL to that hidden field by JavaScript.
Example (using jQuery, but you don't have to) :
$(function() {
// ASP.NET will fill the ID, then # with ID will show to JS as one JS string
var myHiddenField = $('#<%= myServerSideHiddenField.ClientID %>');
var bodyBackground = "url(" + myHiddenField.val() + ")";
document.body.css("background" , bodyBackground);
});