In my asp.net page I have Image control , in which myimage.png will display at page load. Requirement as below, Browse image using File upload control and on click of Upload button , immediate preview need to be displayed in Image control. When upload button is pressed after browsing image, the existing "myimage.png" will be deleted and new image will be saved into sever path with same name and preview need to be displayed in image control.
Issue is After saving image , image control is not displaying the new image immediately. To view the image page need to be re-loaded. Code as below, In aspx page,
<asp:Image ID="imgLogo" style="margin-left: -299px;" ImageUrl="~/images/myimage.png" runat="server" />
Code behind as below,
protected void btnUpload_Click(object sender, EventArgs e)
{
string filePath = FileUpload1.PostedFile.FileName;
File.Delete(Server.MapPath(@"~\images\myimage.png"));
FileUpload1.SaveAs(Server.MapPath(@"~\images\myimage.png"));
imgLogo.ImageUrl = Server.MapPath(@"~\images\myimage.png");
}
Regards