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

<Telerik:RadAjaxPanel> is preventing the "Download" ImageButton from forcing the browser open the "Save As" dialog box.

1 Answer 86 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Mohd
Top achievements
Rank 2
Iron
Mohd asked on 16 Dec 2014, 12:33 PM
Hi every body,

I have a <asp:ImageButton> that is supposed to force the browser to open "Save As" dialog box in attempt to download an image into the client machine.
The image was previously produced successfully in a previous process:

 Using bitmap As New Bitmap(188, 306)
            browser.DrawToBitmap(bitmap, New Rectangle(0, 0, 188, 306))
            Using stream As New MemoryStream()
                bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
                Dim bytes As Byte() = stream.ToArray()
                myImage.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes)
            End Using
 End Using

and is shown successfully within the <asp:Image> tag.


My Download ImageButton has the following code behind:

Private Sub imgbtn_Download_Click(sender As Object, e As ImageClickEventArgs) Handles imgbtn_Download.Click
        Dim bytes As Byte() = Convert.FromBase64String(myImage.ImageUrl.Split(",")(1))
        Response.Clear()
        Response.Buffer = True
        Response.Charset = ""
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
        Response.ContentType = "image/png"
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + "abc.png")
        Response.BinaryWrite(bytes)
        Response.Flush()
        Response.End()
    End Sub

I noticed that if the <asp:ImageButton> was placed inside <Telerik:RadAjaxPanel> the "Save As" dialog box doesn't pop up and the consequently download process doesn't start. However, if I shift the ImageButton control out of the <Telerik:RadAjaxPanel> it works successfuly.

So is there any explanation from Telerik Team why such behavior is taking place. And is there any recommendation to make the "Save As" downlaod process succeeds while the <asp:ImageButton> is inside the <Telerik:RadAjaxPanel>?

Regards;

1 Answer, 1 is accepted

Sort by
0
Accepted
Viktor Tachev
Telerik team
answered on 19 Dec 2014, 08:58 AM
Hello,

The behavior you describe is default browser behavior. In order to download a file you need to temporarily disable AJAX for the ImageButton. Check out the following code snippets that illustrates the approach:


<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="requestStart">
    <asp:ImageButton runat="server" Text="Download" ID="ImageButton1" OnClick="ImageButton1_Click" />
</telerik:RadAjaxPanel>


function requestStart(sender, args) {
    if (args.get_eventTarget().indexOf("ImageButton1") != -1) {
        args.set_enableAjax(false);
    }
}



Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Ajax
Asked by
Mohd
Top achievements
Rank 2
Iron
Answers by
Viktor Tachev
Telerik team
Share this question
or