2009/12/12

[ASP.Net]Dynamically assign your page's background image

I would like to change/assign a page's background image depends on some conditions, and here is what I did.
1.Assign an id to the body and add the runat="server" to it.

2.Add the following code to your code-behind (you can put it in the Page_Load event)
if (ConfigurationManager.ConnectionStrings["MyWebsite"].ConnectionString.Contains("test"))
body1.Style.Add("background-image", @"url(Images/test.jpg)");
else
body1.Style.Add("background-image", @"url(Images/production.jpg)");
Modify the if statement to meet your needs.

No comments:

Post a Comment