I have a Web User Control containing a FormView
. The formview shows details of job seeker. I have provided a button for "Download Resume" link, so that admin/HR can download the resume. I have placed this control in an aspx page that contains the UpdatePanel. Everything works fine except Download Link.
I have given a Command on donwload link button and a function is associated with the command to start download.
Below is the code i have implemented -
//Command on 'Download' link button within FormView protected void lnkDownload_Command(object sender, CommandEventArgs e) { if (e.CommandName.Equals("Download")) { StartDownload(e.CommandArgument.ToString()); } } //My routine to download document //sFileInfo contains filepath$==$mimetype protected void StartDownload(string sFileInfo) { string[] d = sFileInfo.ToString().Split((new string[] { "$==$" }), StringSplitOptions.None); string filename = d[0]; string docType = d[1]; System.IO.FileInfo file = new System.IO.FileInfo(d[0]); if (file.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + d[0]); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = d[1]; Response.WriteFile(file.FullName); Response.End(); } else { Server.Transfer("~/Mesgbox.aspx?cat=2"); } }
The code works perfectly if update panel is removed but generates script errors if update panel is used.
Any suggestions....?
Thanks for sharing your time.
To initiate a full page postback, you add a postback trigger to your update panel:
<asp:UpdatePanel runat="server"> <Triggers> <asp:PostBackTrigger ControlID="YourControlID" /> </Triggers> <ContentTemplate> .....
You cannot return an attachment in an UpdatePanel partial postback, since the results are used by the ScriptManager to update a DIV (not the whole response). The simplest fix for what you're trying to do would be to make your download button as a postback control. That would cause that button to initiate a full postback. Here's the code below to include in your Page_Load
ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(this.lnkDownload);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With