0

I have an ImageButton inside an UpdatePanal, OnClick event, some process is performed on same image, then image saved in the same location.

Problem is, the code behind executes successfully, but result doesn't show on web page.

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 the page manually, results are shown as expected, but Onclick event of the results does not appear, i.e. Changes in image don't appear.

1
  • does image on your folder changes according to your code? does your image visible after on-click event? Commented Apr 19, 2016 at 11:40

1 Answer 1

1

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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.