This is a migrated thread and some comments may be shown as answers.

Show button and then download file doesn't work..

2 Answers 258 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
max
Top achievements
Rank 1
max asked on 17 Mar 2009, 10:28 AM
Hi I've a little problem when I show a button from an Ajaxified control and then I use the button to download a file, I've also tried to register the control but it won't work..

this is the code:
    <asp:ScriptManager ID="ScriptManager1" runat="server"
    </asp:ScriptManager> 
     
    <div> 
        <asp:Button ID="Button1" runat="server" Text="Show" /> 
        <asp:Button ID="Button2" runat="server" Text="Download" Visible="false" /> 
    </div> 
     
    <telerik:radajaxmanager ID="Radajaxmanager1" runat="server" > 
        <AjaxSettings> 
            <Telerik:AjaxSetting AjaxControlID="Button1"
                <UpdatedControls> 
                    <Telerik:AjaxUpdatedControl ControlID="Button2" /> 
                </UpdatedControls> 
            </Telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:radajaxmanager> 


    Private Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button1.Click 
        Button2.Visible = True 
        ScriptManager1.RegisterPostBackControl(Button2) 
    End Sub 
 
    Private Sub Button2_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button2.Click 
 
        Dim fi As New System.IO.FileInfo("C:\test.zip"
 
        If fi.Exists Then 
 
            HttpContext.Current.Response.Buffer = True 
            HttpContext.Current.Response.ClearContent() 
            HttpContext.Current.Response.ClearHeaders() 
            HttpContext.Current.Response.AddHeader("Content-Disposition""attachment; filename=" + fi.Name) 
            HttpContext.Current.Response.ContentType = "application/download" 
            HttpContext.Current.Response.AddHeader("Content-Length", fi.Length) 
            HttpContext.Current.Response.WriteFile(fi.FullName) 
            HttpContext.Current.Response.End() 
            HttpContext.Current.Response.Flush() 
 
        End If 
 
    End Sub 
 

2 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 19 Mar 2009, 02:40 PM
Hi max,

Please review this help topic on how to download files with ajax. Give it a try and let me know if this works for you.

Regards,
Iana
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
max
Top achievements
Rank 1
answered on 19 Mar 2009, 05:24 PM
Thank you for reply,
it could be a partial solution because my goal is to download the file.
The browser, instead, open directly files like pdf, doc, jpg, xls, etc.
Tags
Ajax
Asked by
max
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
max
Top achievements
Rank 1
Share this question
or