• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 508
  • Last Modified:

dynamically change background image of css div

Is there a way to dynamically change the background image of a div tag (server side) that is being used as part of a CSS layout?  if i set that tag to runat=server will that mess up the css styling i have in my style sheet?
0
davidcahan
Asked:
davidcahan
  • 3
  • 3
2 Solutions
 
silemoneCommented:
Yes...you could use runat="server" and it will not mess up css styling...


0
 
jmwheelerCommented:
[Server-Side]
ClientScript.RegisterStartupScript(this.GetType(), "myScriptKey", "document.getElementById('npcontainer').style.background='url(images/mybg.jpg)';", true);
0
 
jmwheelerCommented:
Where npcontainer = the id for the div
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
davidcahanAuthor Commented:
argggg....i'm using a master page so once i set that div to runat server then the id is changing and is no longer the same as in my stylesheet....

jmwheeler will your method work without me having to runat = server on that div?
0
 
jmwheelerCommented:
You can just change the background image client side with no need for "runat=server"

document.getElementById('MyDivID').style.background = 'url(images/mybg.jpg);
0
 
davidcahanAuthor Commented:
yea and just for you to know, the code you provided before (ie ClientScript.RegisterStartupScript etc. etc.) works just fine even with my masterpage
0
 
davidcahanAuthor Commented:
both solutions work, the first one however works server side
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now