473,770 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I update an image without manual refresh?


How can I get an asp:Image to refresh when a user uploads a different jpg.

I disabled caching using this command on Page_Load():
Response.Cache. SetCacheability (HttpCacheabili ty.No Cache);
but it didn't help.
The problem is that this page does not change images after a client uploads
a new one. If I hit the browser's refresh, then I can see the updated image,
but if I don't refresh, then I see the previous image.
The code to change the image is this simple: imgControl.Imag eUrl =
"http://imagePath.jpg";

The new image does have the same name as the old image, but why should this
matter? If the browser is caching then why does it work using a refresh,
wouldn't it still use the image from the cache?
--
Jerry J
Nov 6 '06 #1
11 5671
You can trick the browser into getting the image from the server rather than
from the cache by adding a random query parameter to the image source.

I use the following javascript code to generate random numbers:

function random(){

return (new Date()).getMill iseconds();

}
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Jerry J" <Je****@discuss ions.microsoft. comwrote in message
news:32******** *************** ***********@mic rosoft.com...
>
How can I get an asp:Image to refresh when a user uploads a different jpg.

I disabled caching using this command on Page_Load():
Response.Cache. SetCacheability (HttpCacheabili ty.No Cache);
but it didn't help.
The problem is that this page does not change images after a client
uploads
a new one. If I hit the browser's refresh, then I can see the updated
image,
but if I don't refresh, then I see the previous image.
The code to change the image is this simple: imgControl.Imag eUrl =
"http://imagePath.jpg";

The new image does have the same name as the old image, but why should
this
matter? If the browser is caching then why does it work using a refresh,
wouldn't it still use the image from the cache?
--
Jerry J

Nov 6 '06 #2
On 11/06/06 07:12, Jerry J wrote:
How can I get an asp:Image to refresh when a user uploads a different jpg.

I disabled caching using this command on Page_Load():
Response.Cache. SetCacheability (HttpCacheabili ty.No Cache);
but it didn't help.
To understand the problem, we need to think back to when this image was
initially sent to the client browser. At that time, it was sent with an
expiration date/time which was probably pretty for into the future. This
is to allow the client to cache the image, so it won't have to keep pulling
it down over the wire.

So, even if you change the expiration for the image, the client still has
the original expiration, and won't even try to get a new copy of the image
until the expiration time expires, or the client's cache is flushed.

However, there are a couple easy work arounds for this. The one I prefer
is to simply change the name of the image file (as well as the reference
to the file in your generated HTML page). The client's cache is based on
the name of the resource, and if that name changes, such that the client
doesn't already have it in its cache, it will download it.

Of course, to allow the client to cache the content when possible, you only
want to change the name of the file when the image really changes.

>

The problem is that this page does not change images after a client uploads
a new one. If I hit the browser's refresh, then I can see the updated image,
but if I don't refresh, then I see the previous image.
The code to change the image is this simple: imgControl.Imag eUrl =
"http://imagePath.jpg";

The new image does have the same name as the old image, but why should this
matter?
Let me know if you still don't see why...
If the browser is caching then why does it work using a refresh,
wouldn't it still use the image from the cache?
As you've seen, when you issue a refresh, it causes the client to bypass
its cache. This is client specific, but I think most browsers do this.
>
Nov 6 '06 #3
Mark,

I don't want to change the name of my image. What was your other work around?

Thanks for the response.

--
Jerry J
"Mark E. Hansen" wrote:
On 11/06/06 07:12, Jerry J wrote:
How can I get an asp:Image to refresh when a user uploads a different jpg.

I disabled caching using this command on Page_Load():
Response.Cache. SetCacheability (HttpCacheabili ty.No Cache);
but it didn't help.

To understand the problem, we need to think back to when this image was
initially sent to the client browser. At that time, it was sent with an
expiration date/time which was probably pretty for into the future. This
is to allow the client to cache the image, so it won't have to keep pulling
it down over the wire.

So, even if you change the expiration for the image, the client still has
the original expiration, and won't even try to get a new copy of the image
until the expiration time expires, or the client's cache is flushed.

However, there are a couple easy work arounds for this. The one I prefer
is to simply change the name of the image file (as well as the reference
to the file in your generated HTML page). The client's cache is based on
the name of the resource, and if that name changes, such that the client
doesn't already have it in its cache, it will download it.

Of course, to allow the client to cache the content when possible, you only
want to change the name of the file when the image really changes.



The problem is that this page does not change images after a client uploads
a new one. If I hit the browser's refresh, then I can see the updated image,
but if I don't refresh, then I see the previous image.
The code to change the image is this simple: imgControl.Imag eUrl =
"http://imagePath.jpg";

The new image does have the same name as the old image, but why should this
matter?

Let me know if you still don't see why...
If the browser is caching then why does it work using a refresh,
wouldn't it still use the image from the cache?

As you've seen, when you issue a refresh, it causes the client to bypass
its cache. This is client specific, but I think most browsers do this.
Nov 6 '06 #4
Eliyahu,

Not sure what you mean here? What happens when the client executes that JAVA
script?

--
Jerry J
"Eliyahu Goldin" wrote:
You can trick the browser into getting the image from the server rather than
from the cache by adding a random query parameter to the image source.

I use the following javascript code to generate random numbers:

function random(){

return (new Date()).getMill iseconds();

}
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Jerry J" <Je****@discuss ions.microsoft. comwrote in message
news:32******** *************** ***********@mic rosoft.com...

How can I get an asp:Image to refresh when a user uploads a different jpg.

I disabled caching using this command on Page_Load():
Response.Cache. SetCacheability (HttpCacheabili ty.No Cache);
but it didn't help.
The problem is that this page does not change images after a client
uploads
a new one. If I hit the browser's refresh, then I can see the updated
image,
but if I don't refresh, then I see the previous image.
The code to change the image is this simple: imgControl.Imag eUrl =
"http://imagePath.jpg";

The new image does have the same name as the old image, but why should
this
matter? If the browser is caching then why does it work using a refresh,
wouldn't it still use the image from the cache?
--
Jerry J


Nov 6 '06 #5
On 11/06/06 08:20, Jerry J wrote:
Mark,

I don't want to change the name of my image. What was your other work around?
You can add parameters on to the end of the url. For example, if you're
image is accessed as http://mysite/images/myimage.jpg, you can change
it to be http://mysite/images/myimage.jpg?my-random-value

You can change the random value anytime you want the clients to bypass
the cache a fetch a new version of the image.

>
Thanks for the response.
Nov 6 '06 #6
Oh, I understand, like this ->
"http://imagePath.jpg?s omethinghere=di fferentValueEve ryTime"

I will try that!

--
Jerry J
"Eliyahu Goldin" wrote:
You can trick the browser into getting the image from the server rather than
from the cache by adding a random query parameter to the image source.

I use the following javascript code to generate random numbers:

function random(){

return (new Date()).getMill iseconds();

}
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Jerry J" <Je****@discuss ions.microsoft. comwrote in message
news:32******** *************** ***********@mic rosoft.com...

How can I get an asp:Image to refresh when a user uploads a different jpg.

I disabled caching using this command on Page_Load():
Response.Cache. SetCacheability (HttpCacheabili ty.No Cache);
but it didn't help.
The problem is that this page does not change images after a client
uploads
a new one. If I hit the browser's refresh, then I can see the updated
image,
but if I don't refresh, then I see the previous image.
The code to change the image is this simple: imgControl.Imag eUrl =
"http://imagePath.jpg";

The new image does have the same name as the old image, but why should
this
matter? If the browser is caching then why does it work using a refresh,
wouldn't it still use the image from the cache?
--
Jerry J


Nov 6 '06 #7
The browser will think it is a different image and will get it from the
server.

It doesn't have to be in javascript. If you do it on server side, you can
use the Random class for generating random numbers and adding them to the
image url.

imgControl.Imag eUrl = "http://imagePath.jpg?" +
myFunctionThatG etsRandomString ();

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Jerry J" <Je****@discuss ions.microsoft. comwrote in message
news:5D******** *************** ***********@mic rosoft.com...
Eliyahu,

Not sure what you mean here? What happens when the client executes that
JAVA
script?

--
Jerry J
"Eliyahu Goldin" wrote:
>You can trick the browser into getting the image from the server rather
than
from the cache by adding a random query parameter to the image source.

I use the following javascript code to generate random numbers:

function random(){

return (new Date()).getMill iseconds();

}
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Jerry J" <Je****@discuss ions.microsoft. comwrote in message
news:32******* *************** ************@mi crosoft.com...
>
How can I get an asp:Image to refresh when a user uploads a different
jpg.

I disabled caching using this command on Page_Load():
Response.Cache. SetCacheability (HttpCacheabili ty.No Cache);
but it didn't help.
The problem is that this page does not change images after a client
uploads
a new one. If I hit the browser's refresh, then I can see the updated
image,
but if I don't refresh, then I see the previous image.
The code to change the image is this simple: imgControl.Imag eUrl =
"http://imagePath.jpg";

The new image does have the same name as the old image, but why should
this
matter? If the browser is caching then why does it work using a
refresh,
wouldn't it still use the image from the cache?
--
Jerry J



Nov 6 '06 #8
This works, thank you!

--
Jerry J
"Mark E. Hansen" wrote:
On 11/06/06 08:20, Jerry J wrote:
Mark,

I don't want to change the name of my image. What was your other work around?

You can add parameters on to the end of the url. For example, if you're
image is accessed as http://mysite/images/myimage.jpg, you can change
it to be http://mysite/images/myimage.jpg?my-random-value

You can change the random value anytime you want the clients to bypass
the cache a fetch a new version of the image.


Thanks for the response.
Nov 6 '06 #9
This works thank you!
--
Jerry J
"Eliyahu Goldin" wrote:
The browser will think it is a different image and will get it from the
server.

It doesn't have to be in javascript. If you do it on server side, you can
use the Random class for generating random numbers and adding them to the
image url.

imgControl.Imag eUrl = "http://imagePath.jpg?" +
myFunctionThatG etsRandomString ();

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Jerry J" <Je****@discuss ions.microsoft. comwrote in message
news:5D******** *************** ***********@mic rosoft.com...
Eliyahu,

Not sure what you mean here? What happens when the client executes that
JAVA
script?

--
Jerry J
"Eliyahu Goldin" wrote:
You can trick the browser into getting the image from the server rather
than
from the cache by adding a random query parameter to the image source.

I use the following javascript code to generate random numbers:

function random(){

return (new Date()).getMill iseconds();

}
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Jerry J" <Je****@discuss ions.microsoft. comwrote in message
news:32******** *************** ***********@mic rosoft.com...

How can I get an asp:Image to refresh when a user uploads a different
jpg.

I disabled caching using this command on Page_Load():
Response.Cache. SetCacheability (HttpCacheabili ty.No Cache);
but it didn't help.
The problem is that this page does not change images after a client
uploads
a new one. If I hit the browser's refresh, then I can see the updated
image,
but if I don't refresh, then I see the previous image.
The code to change the image is this simple: imgControl.Imag eUrl =
"http://imagePath.jpg";

The new image does have the same name as the old image, but why should
this
matter? If the browser is caching then why does it work using a
refresh,
wouldn't it still use the image from the cache?
--
Jerry J


Nov 6 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5550
by: querypk | last post by:
Hi I would like to know how to resize an Image without using python Imaging library.
0
246
by: Michael Gorski | last post by:
In c# is there a way to print an image without viewing it? I have the location of the file, all I need to do is print the image with no interaction from the user
0
1166
by: Klemens | last post by:
New Database. Structure created with db2look. Data for all Tables filled with load from original Database. Need for Replication to go on without full refresh. Database UDB8.1 on Win2000 Any help? Thanks
0
1914
by: Mattia | last post by:
************************************************** Manage image without exhausted memory ************************************************** Hi; I have a big problem. I must create a script that upload an image an then resize it, if width or height are more than 250px. Now, after upload an image (in this example I suppose that it's a JPEG image):
5
8627
by: mattcolenutt | last post by:
Scenario: Have a product form with an "image location" field. The image property uses this field to display the image. Problem: If an image location field has been changed, the image will not refresh, even after putting a "refresh", or "repaint" or "requery" statement in the afterupdate event. The only way to make it update is to move to the next record and then move back again. Private Sub Stock_ImageLocation_AfterUpdate()
8
4523
by: m1post | last post by:
Hi, I'm very much a novice, and wondered if someone could help. I'll try to be as specific as possible, but don't waant you to have to read too much. I have 2 pages in the sequence. 1st allows customers to login, passing control to the 2nd, which on entry returns their balance details from my DB (using their Reference 'BookingRef = Request.form("txtBookingRef")') and displays an additional section allowing them to enter an amount of a part...
5
4595
onlymars
by: onlymars | last post by:
helloo guys, i have an image gallery page which have thumbnails at the bottom of the screen and the main image is in the middle of the page, i want that users click on the thumbnail pic's and the main image changes accordingly but with out a page refresh. have searched a lot but am not getting a solution, your help will be very appreciated. thanx.
1
3582
by: w.l.fischer | last post by:
Hi, the following sequence: set current explain mode yes; set current explain snapshot yes; update ...; set current explain mode no;
1
2551
by: rahullko05 | last post by:
one line code to replace an image without page refresh
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.