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;
}
}
和photoInst是图像不刷新。但是当我点击f5时,图像将被刷新。有什么帮助吗?
答案 0 :(得分:3)
听起来像浏览器正在缓存图像。对于ghetto修复,您可以使用时间戳将查询字符串添加到图像引用。
photoInst.ImageUrl = "~/Upload/user" + id + string.Format("/gfx/photoInst.jpg?{0}", DateTime.Now.Ticks);
看看它是否适合你。
祝你好运!