locked
How to download file from in ajax? RRS feed

  • Question

  • User1382645016 posted

    Hi,

    I have a gridview having a link button for download a file.Whenever user click on the button,the corresponding file is downloaded.The problem is that my gridview is in the update panel and i am unable to perform the download operation.Even i tried to add the trigger in the gridrow event for this link button.But still its not working.

    Thanks in Advance

    Monday, March 23, 2009 1:42 AM
  • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 23, 2009 11:23 PM

All replies

  • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 23, 2009 11:23 PM
  • User-1025751665 posted
    Hey i gottttttttttttttttt it !!!!! problem is from partial post back(update panel). All u need to full postback to the particular button or any control.. change update panel mode to Conditional and add postbacktrigger for particular control. check the below code. <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <Triggers> <asp:PostBackTrigger ControlID="DownloadAll" /> </Triggers> <asp:Button ID="DownloadAll" runat="server" Text="Generate Report" OnClick="DownloadAll_Click" /> </ContentTemplate> </asp:UpdatePanel> Regards Selva
    Friday, April 3, 2009 12:49 PM
  • User-1025751665 posted
    Hey i gottttttttttttttttt it !!!!! problem is from partial post back.All u need full post back to the particular button r any control.. add postbacktrigger for updatepanel. check the below code. <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <Triggers> <asp:PostBackTrigger ControlID="DownloadAll" /> </Triggers> <asp:Button ID="DownloadAll" runat="server" Text="Generate Report" OnClick="DownloadAll_Click" /> </ContentTemplate> </asp:UpdatePanel> protected void DownloadAll_Click(object sender, EventArgs e) { DownloadFile(url); } public void DownloadFile(string url) { string URL = url; System.IO.FileInfo fileInfo = new System.IO.FileInfo(URL); if (fileInfo.Exists) { HttpContext.Current.Response.ContentType = "application/zip"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(fileInfo.Name)); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.WriteFile(fileInfo.FullName); HttpContext.Current.Response.End(); } } Regards selva chennai india
    Friday, April 3, 2009 12:54 PM
  • User-1025751665 posted
    sorry my previous message not displayed correctly. <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <Triggers> <asp:PostBackTrigger ControlID="DownloadAll" /> </Triggers> <ContentTemplate> <asp:Button ID="DownloadAll" runat="server" Text="Generate Report" OnClick="DownloadAll_Click" /> </ContentTemplate> </asp:UpdatePanel> Regards selva
    Friday, April 3, 2009 12:56 PM
  • User-319574463 posted

     To get your code to display properly, please:

    1. Click on Edit Profile
    2. Select Site Options
    3. Change content editor to enhanced
    4. Click Save
    5. When you next post in either IE or Firefox, you will have an additional tool-bar. At the top right is a button for a code insertion window.
    Friday, April 3, 2009 1:23 PM
  • User729069081 posted

    Is it possible for someone to explain how does micrsoft does it w/o postback

     

    see it for yourself.

     

    http://ajaxcontroltoolkit.codeplex.com/releases/view/43475

     

    Click on the download button

     

    "Application Ajax Control Toolkit .NET 3.5 - Binary

    Wednesday, April 28, 2010 2:14 PM
  • User-579933967 posted

    Thnks buddy it worked for me 

    Tuesday, October 5, 2010 10:00 AM