Solved

how can I force the browser to appreciate a change to the background image on an asp page.

Posted on 2011-09-29
10
229 Views
Last Modified: 2012-06-27
this is driving me mad!

my background image is defined in css and I have an asp page that allows the user to change the contents of that image file (background.jpg) defined in the css.

my problem is that whenever the background.jpg image file is replaced using vb code I still have to tell the user to hit F5 for the change to show in the browser. All browsers seem to remember the previous image and always use that one instead of the incumbent one.

So what do I have to do to ensure that the new background image is immediately applied when returning to the homepage after selecting a new image.
0
Comment
Question by:JOHNFROG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 1

Expert Comment

by:Doddsy1000
ID: 36815290
Can you run F5 as a macro? Maybe execute it from the return to the homepage?

If you can, maybe shift & f5 to overcome the cache.

Either that, or you might find what you are after in the security/miscellaneous section of "internet properties" in control panel.

good luck with that.

cheers

Ian
0
 
LVL 30

Expert Comment

by:LZ1
ID: 36815341
You have a couple of different ways to do it.
1) You could add the meta no cache to the head of your site
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

2) You could time stamp your CSS file:



<link rel="stylesheet" type="text/css" href="style.css?<%response.write(time())%>">

Open in new window

0
 

Author Comment

by:JOHNFROG
ID: 36815584
LZ1 - Have tried that but still dont get the desired effect unless I hit F5.

No matter which browser I use the change is not observed unless I hit F5.

When I look at other websites that let you change the theme it works so why not my website? driving me crazy!

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:LZ1
ID: 36815600
Even the time stamp doesn't work?
0
 

Author Comment

by:JOHNFROG
ID: 36815673
no. time stamp doesnt work. wish it did though. must be something on the server maybe.
0
 
LVL 30

Expert Comment

by:LZ1
ID: 36815746
I was just going to suggest that. It could be something with IIS.  However, what happens if you try to add anything else dynamically like
styles.css?token=1234

I know the timestamp didn't work, but does that work?
0
 

Author Comment

by:JOHNFROG
ID: 36815925
To be Honest - I dont really know how to test that. (token=1234). If I add it to the css line how do I know if it is being added?

Is there a way to point to a different file in css rather that changing the contents of the file being pointed to.

0
 
LVL 7

Accepted Solution

by:
NauticalNonsense earned 500 total points
ID: 36817570
Can you change your code to use HTML for the background image (instead of the CSS)?

<body runat="server" id="body">

and then add a

body.Attributes.Add("style", "background-image: url(images/pattern.png?" + System.DateTime.Now.ToString());

type of thing?

I've had to use additional info after images to get them to load every time, so maybe this will work for ya.
0
 

Author Closing Comment

by:JOHNFROG
ID: 36819011
you know I really thought that would have worked. but still - the F5 must be used.

It occurs to me that I cannot change the contents of an image file and expect the server to realize it has changed. So I must revert to pointing the background to a new file each time.

So I used the
 body.Attributes.Add("style", "background-image: url( ....
example and am storing the required image url in the database.

hallelujah ... it works a treat. And using the database solution I can control tiling etc better and even keep track of different backgrounds for each individual page.

Worked out alot better than I intended.

Thanks to all those who have helped but points must go to nautical nonsense.
0
 
LVL 7

Expert Comment

by:NauticalNonsense
ID: 36819036
ssssssssshhpow!

happy it worked for you :)
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS style formatting? 2 55
CSS Won't Show Up On Drupal Omega Sub-Theme 1 29
asp.net, radiobuttonlist, c# 3 66
bulk load multiple users for aspnetusers table 2 10
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question