0
votes

I have an ImageButton inside an UpdatePanal, OnClick event, Some process is preformed on same image. than Image save on same location.

Problem is, The Code Behind Executes Successfully, But result doesn't show on Webpage

ASP Code:

<asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" ChildrenAsTriggers="True" UpdateMode="Always" runat="server">
        <ContentTemplate>  
            <asp:ImageButton  ID="ImageButton1" runat="server" AutoPostBack="true" ImageUrl="~/Sel_Img/test.jpg" OnClick="ImageButton1_Click" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ImageButton1" />
        </Triggers>
    </asp:UpdatePanel>

Code Behind

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
   using (Bitmap bitmap = new Bitmap((Server.MapPath(@"/Sel_Img/test.jpg")))
   Bitmap bmp = Some_Process(bitmap);
   bitmap.Dispose();
   bmp.Save(Server.MapPath(@"/Sel_Img/test.jpg"));
   ImageButton1.ImageUrl = "../Sel_Img/test.jpg";
}

When i reload Page Manually, Results shown as expected, But Onclick Event the results does not appear , I.E Changes in Image Doesn't Appear.

1
does image on your folder changes according to your code? does your image visible after on-click event? - Rojalin Sahoo

1 Answers

1
votes

The change doesn't appear because the image is in the browser cache. To force a refresh, you can append to the URL a different query string every time the image is modified:

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    ...
    ImageButton1.ImageUrl = "~/Sel_Img/test.jpg?" + DateTime.Now.Ticks.ToString();
}