Hi comunidadmexi...,
You are redirecting to a page that downloads a file. The screen doesn't update in that case, so the image stays.
You could either make the file download on the same page or make the redirect via script after the postback.
Check this example. Now please take its reference and correct your code.
HTML
<asp:ScriptManager runat="server">
</asp:ScriptManager>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:TemplateField>
<ItemTemplate>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div class="modal">
<div class="center">
<img alt="" src="loader.gif" />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="/img/download.gif"
OnClick="ImageButton1_Click"
CommandArgument='<%# Eval("Id") %>' />
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
CSS
<style type="text/css">
body {
margin: 0;
padding: 0;
font-family: Arial;
font-size: 10pt;
}
.modal {
position: fixed;
left: 0;
z-index: 999;
height: 100%;
width: 100%;
top: 0;
background-color: Black;
filter: alpha(opacity=60);
opacity: 0.6;
-moz-opacity: 0.8;
}
.center {
z-index: 1000;
margin: 30px auto;
padding: 10px;
width: 130px;
background-color: White;
border-radius: 10px;
filter: alpha(opacity=100);
opacity: 1;
-moz-opacity: 1;
}
.center img {
height: 128px;
width: 128px;
}
</style>
Code
Default
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindGrid();
}
}
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);
}
protected void BindGrid()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3]
{
new DataColumn("Id"),
new DataColumn("Name"),
new DataColumn("Country")
});
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
GridView1.DataSource = dt;
GridView1.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
BindGrid()
End If
End Sub
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
Dim ImageButton1 As ImageButton = CType(sender, ImageButton)
Dim sIDint As String = ImageButton1.CommandArgument.ToString()
Thread.Sleep(3000)
Dim cookie As HttpCookie = New HttpCookie("ExcelDownloadFlag") With {
.Value = "Flag",
.Expires = DateTime.Now.AddDays(1)
}
Response.AppendCookie(cookie)
ScriptManager.RegisterStartupScript(Me, GetType(String), "OpenWindow", "window.open('pdf.aspx?sID=" & sIDint & "');", True)
End Sub
Protected Sub BindGrid()
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(2) {New DataColumn("Id"), New DataColumn("Name"), New DataColumn("Country")})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
PDF
C#
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["sID"];
string filePath = Server.MapPath("loader.gif");
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(filePath));
Response.WriteFile(filePath);
Response.End();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim id As String = Request.QueryString("sID")
Dim filePath As String = Server.MapPath("loader.gif")
Response.ContentType = ContentType
Response.AppendHeader("Content-Disposition", "attachment; filename=" & System.IO.Path.GetFileName(filePath))
Response.WriteFile(filePath)
Response.End()
End Sub
Screenshot