This is something i had to look up. It’s realy easy though but it feels a bit hacky:

body id=”bodytag” runat=”server”

So as you see i have added a runat=”server” tag to the body tag. This basically makes sure our server code is aware of the body element.
I’ve also given it an id so i can address the control in the code-behind.

In the code-behind we can now add a style attribute (or class if you wish) to the bodytag:

bodytag.Attributes.Add(“style”, “background: url(‘images/logos/bmw.jpg’) #F0F0F0 right bottom no-repeat; height: 100%;”);

  2 Responses to “How to change a body background in ASP.NET”

  1. Why not with regular css?

  2. I needed to have another background image in certain cases. this way you can format your background image e.g. String.Format(“background: url(’images/logos/{0}.jpg’)”, currentBrand);

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2012 Dries Hoebeke on .NET Suffusion theme by Sayontan Sinha