Jon
Jon

Reputation: 301

Refresh webpage to get new picture

Ok, here's my setup: I have an aspx content page with a vb.net backend. The page is basically a user profile style page. I'm adding a photo section to the page... the upload and delete works fine... starts with a placeholder image, user can select a file, upload it (which is then saved in a subdirectory of images with the user's id as filename), and the page redirects (reloads) itself and after that you can see the image uploaded. Works fine in reverse as well- deleting it gets rid of the file and the page reloads and displays the placeholder image.

The problem I'm hitting is if they select one file, upload it, but then want to change it. It deletes the old file just fine, and saves the new file as userID.jpg, however, when I do the response.redirect, the old image is still displayed. I assume this is because the image is cached (since it has the same filename.) a manual refresh in the browser sets it right, but I'd like to avoid telling the user they need to do this :/ I saw on MSDN that there was a webBrowser.Refresh method, but I think I am missing something because intellisense gave me the squiggles of death on that one, and I've also tried server.transfer with no change. I tried...

Response.CacheControl = "no-cache"
Response.AddHeader("Pragma", "no-cache")
Response.Expires = -1

Still didn't work. The only option I've seen that I haven't explored was adding similar code in meta tags, which I've seen can contain the no-cache bit, or an expires timeout to force the reload, but I don't know that it would have different results, and that would involve mucking about with the master page, which is used by many other content pages... any ideas on how I can get this picture to reload itself?

Upvotes: 0

Views: 241

Answers (2)

Jon
Jon

Reputation: 301

Here's how I got around it: Changed my image tag to a asp:image control. Then, during page load, added a query string with now.ticks.tostring() to the control.imageURL.

Upvotes: 0

Enrique Zavaleta
Enrique Zavaleta

Reputation: 2108

You can try sending a Javascript code block to the browser to refresh the page if you are OK with that, just write this in your event method:

ScriptManager.RegisterStartupScript(this, this.GetType(), "reloadPage", "location.reload();", true);

Upvotes: 1

Related Questions