Eyad Shahroury

Eyad Shahroury

  • NA
  • 32
  • 2.5k

Ajax Problem With Downloading File

May 16 2020 10:58 AM
I have problem with ajax manager :
 
JavaScript:
 
I used this function to allow me download a file from gridview
  1. function onRequestStart(sender, args)  
  2. {  
  3. if (args.get_eventTarget().indexOf("imgDownload") >= 0)  
  4. args.set_enableAjax(false);  
  5. }  
My Ajax Manager:
  1. <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" LoadingPanelID="gridLoadingPanel" ClientEvents-OnRequestStart="onRequestStart">  
  2. <AjaxSettings>  
  3. <telerik:AjaxSetting AjaxControlID="SearchRadButton">  
  4. <UpdatedControls>  
  5. <telerik:AjaxUpdatedControl ControlID="AttachmentRadGridView" />  
  6. <telerik:AjaxUpdatedControl ControlID="AttachmentRecordRadLabel" />  
  7. </UpdatedControls>  
  8. </telerik:AjaxSetting>  
  9. <telerik:AjaxSetting AjaxControlID="AttachmentRadGridView">  
  10. <UpdatedControls>  
  11. <telerik:AjaxUpdatedControl ControlID="AttachmentRadGridView" LoadingPanelID="gridLoadingPanel">  
  12. </telerik:AjaxUpdatedControl>  
  13. </UpdatedControls>  
  14. </telerik:AjaxSetting>  
  15. </AjaxSettings>  
  16. </telerik:RadAjaxManager>  
My GridView Where I The button for download exist:
  1. <telerik:GridTemplateColumn HeaderText="Request Download" ItemStyle-HorizontalAlign="Center">  
  2. <ItemTemplate>  
  3. <asp:ImageButton ID="imgDownload" runat="server" ImageUrl="/images/attachment24.png"  
  4. CommandName="download_file" Height="22px" Width="22px" ToolTip="Request Download"  
  5. CommandArgument='<%# Eval("ID") %>' />  
  6. </ItemTemplate>  
  7. </telerik:GridTemplateColumn>  
CodeBehind:
  1. Protected Sub AttachmentRadGridView_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles AttachmentRadGridView.ItemCommand  
  2. If e.CommandName = "download_file" Then  
  3. Dim ditem As GridDataItem = CType(e.Item, GridDataItem)  
  4. Dim AttachID As Long = CLng(ditem("ID").Text)  
  5. DownloadFileAttachment(AttachID)  
  6. End If  
  7. End Sub  
  8. Protected Sub DownloadFileAttachment(ByVal FileId As Long)  
  9. 'Dim id As Integer = Integer.Parse(TryCast(sender, LinkButton).CommandArgument)  
  10. Dim bytes As Byte()  
  11. Dim fileName As String, contentType As String  
  12. Dim constr As String = dbpath  
  13. Using con As New SqlConnection(constr)  
  14. Using cmd As New SqlCommand()  
  15. cmd.CommandText = "select FileName, ImageData, FileType from FileStore where FileId=@FileId"  
  16. cmd.Parameters.AddWithValue("@FileId", FileId)  
  17. cmd.Connection = con  
  18. con.Open()  
  19. Using sdr As SqlDataReader = cmd.ExecuteReader()  
  20. sdr.Read()  
  21. bytes = DirectCast(sdr("ImageData"), Byte())  
  22. contentType = sdr("FileType").ToString()  
  23. fileName = sdr("FileName").ToString() & "." & contentType  
  24. End Using  
  25. con.Close()  
  26. End Using  
  27. End Using  
  28. Dim path As String = MapPath("/Download/" & fileName)  
  29. Response.Clear()  
  30. Response.Buffer = True  
  31. Response.Charset = ""  
  32. Response.Cache.SetCacheability(HttpCacheability.NoCache)  
  33. Response.ContentType = contentType  
  34. Response.AppendHeader("Content-Disposition""attachment; filename=" + fileName)  
  35. Response.BinaryWrite(bytes)  
  36. Response.Flush()  
  37. Response.End()  
  38. End Sub  
Downloading file working well , but anything else stoped like filtering gridview ,sorting gridview and etc (look like ajax post back stoped)
 
how can I force ajax manager working again after downloading file ( after calling onRequestStart)
 
Please Help me
 
Thank in advance

Answers (3)