Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

download file in asp.net

I'm using following code to download file. the problem is onupdate event of UpdatePanelAnimationExtender is not calling. Seeking help
Serach.aspx
------------------------
<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
  <cc1:UpdatePanelAnimationExtender ID="UpdatePanelAnimationExtender1" runat="server"
        TargetControlID="Up1">
        <Animations>
        <OnUpdating>
        <FadeOut Duration=".5" Fps="18" MinimumOpacity=".5" />
     </OnUpdating>
        <OnUpdated><FadeIn Duration=".5" Fps="18" /></OnUpdated>
        </Animations>
    </cc1:UpdatePanelAnimationExtender>
    
    <asp:UpdatePanel ID="Up1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
 <asp:Button SkinID="brownish" ID="btnLabelTop" runat="server" Text="Label" OnClick="btnLabelTop_Click"  />
 </ContentTemplate>
        <Triggers>
           
            <asp:AsyncPostBackTrigger ControlID="btnLabelTop" EventName="Click" />
        />
        </Triggers>
    </asp:UpdatePanel>
 
-------------------------
search.cs
-------------------------------
button click code 
 protected void btnLabelTop_Click(object sender, EventArgs e)
    {
 
-
-
-some code--
-
Response.Redirect("Download.aspx", true);
}
 
------------------------------------
Download.aspx
--------------------------------------
 
 protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            DownloadFile("labels.csv", true);
 
        }
        catch (Exception ex)
        {
        }
    }
    /// <summary>
    /// Download csv file
    /// </summary>
    /// <param name="fname"></param>
    /// <param name="forceDownload"></param>
    private void DownloadFile(string fname, bool forceDownload)
    {
        string path = Server.MapPath(Request.ApplicationPath) + "\\csv\\" + fname;
        string name = Path.GetFileName(path);
        string ext = Path.GetExtension(path);
        string type = "";
        // set known types based on file extension  
        if (ext != null)
        {
            switch (ext.ToLower())
            {
                case ".csv":
                    type = "text/csv";
                    break;
 
                case ".txt":
                    type = "text/plain";
                    break;
 
                case ".doc":
                case ".rtf":
                    type = "Application/msword";
                    break;
                case ".pdf":
                    type = "Application/pdf";
                    break;
            }
        }
        if (forceDownload)
        {
            Response.AppendHeader("content-disposition", "attachment; filename=" + name);
 
            Response.AppendHeader("Content-Transfer-Encoding", "binary");
            Response.Expires = 0;
            Response.AppendHeader("Pragma", "cache");
            Response.AppendHeader("Cache-control", "private");
        }
        if (type != "")
            Response.ContentType = type;
        Response.WriteFile(path);
        Response.End();
    }

Open in new window

0
chrisy
Asked:
chrisy
1 Solution
 
GiftsonDJohnCommented:
Hi,

You have put UpdateMode="Conditional" in UpdatePanel declaration. If you are using Conditional, the update panel will not update until you call UpdatePanel1.Update();

Try this.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now