C# ASP.NET - Not able to hide image in updateprogress after response redirect

244 views Asked by At

I have one Ajax UpdateProgress for only one UpdatePanels in the page.

The updatepanel has a gridview with a download button.

Once user clicks on the button, the 'wait' Image shows up, but keeps showing even after the download is complete.

How should I hide it, once the download is done.

My code below but not working, because the image is showing even after the download is complete.

.cs

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    ImageButton ImageButton1 = (ImageButton)sender;
    sIDint = ImageButton1.CommandArgument.ToString();

    Thread.Sleep(3000);
    HttpCookie cookie = new HttpCookie("ExcelDownloadFlag")
    {
        Value = "Flag",
        Expires = DateTime.Now.AddDays(1)
    };
    Response.AppendCookie(cookie);
    Response.Redirect("pdf.aspx?sID=" + sIDint.ToString());

    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "HideImage();", true);
    ImageButton imgLike = (ImageButton)FindControl("imgLike");

    if (imgLike != null)
    {
        imgLike.Visible = false;
    }
}

.aspx

function HideImage() {
    $(#imgLike).hide();
}

<asp:TemplateField HeaderText="Dwn">
    <ItemTemplate>
        <asp:UpdateProgress ID="UpdateProgress1" runat="server"
            AssociatedUpdatePanelID="UpdatePanel1">
            <ProgressTemplate>
                <div class="modal">
                    <div class="center">
                        <img alt="" src="/Img/ajax-loader.gif" id="imgLike" />
                    </div>
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ImageButton1" />
            </Triggers>
            <ContentTemplate>
                <asp:ImageButton ID="ImageButton1" runat="server"
                    ImageUrl="/img/download.gif"
                    OnClick="ImageButton1_Click"
                    CommandArgument='<%# Eval("ID") %>' />
            </ContentTemplate>
        </asp:UpdatePanel>
    </ItemTemplate>
</asp:TemplateField>

Edit

Solved using

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
    ImageButton ImageButton1 = (ImageButton)sender;
    string sIDint = ImageButton1.CommandArgument.ToString();
 
    Thread.Sleep(3000);
    HttpCookie cookie = new HttpCookie("ExcelDownloadFlag")
    {
        Value = "Flag",
        Expires = DateTime.Now.AddDays(1)
    };
    Response.AppendCookie(cookie);
    ScriptManager.RegisterStartupScript(this, typeof(string), "OpenWindow", "window.open('pdf.aspx?sID=" + sIDint + "');", true);
}
0

There are 0 answers