Reputation: 5941
i have weird problem, I upload image this way :
protected void UploadButton_Click(object sender, EventArgs e)
{
try
{
var row = MainUserGridView.SelectedRow;
if (String.IsNullOrEmpty(row.Cells[0].Text)) return;
var id = int.Parse(row.Cells[0].Text);
var filePath = Server.MapPath("~//Upload");
if (!Directory.Exists(filePath + "//user" + id + "//gfx"))
Directory.CreateDirectory(filePath + "//user" + id + "//gfx");
if (FileUploadControl.FileName.ToLower().Contains(".jpg"))
{
FileUploadControl.SaveAs(filePath + "//user" + id + "//gfx//photoInst.jpg");
}
photoInst.ImageUrl = "~/Upload/user" + id + "/gfx/photoInst.jpg";
StatusLabel.Text = "File uploaded!";
}
catch (Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
and photoInst which is image isn't refreshed. But when I hit f5 then image will be refreshed. Any help ?
Upvotes: 1
Views: 755
Reputation: 1513
Sounds like the browser is caching the image. For a ghetto fix, you can add a query string to the image reference with the timestamp.
photoInst.ImageUrl = "~/Upload/user" + id + string.Format("/gfx/photoInst.jpg?{0}", DateTime.Now.Ticks);
See if that works for you.
Good luck!
Upvotes: 4