Click here to Skip to main content
15,029,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I have problem with ajax manager :

JavaScript:

I used this function to allow me download a file from gridview
JavaScript
function onRequestStart(sender, args) {
    if (args.get_eventTarget().indexOf("imgDownload") >= 0)
        args.set_enableAjax(false);
    }
}

My Ajax Manager:
ASPX
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" LoadingPanelID="gridLoadingPanel" ClientEvents-OnRequestStart="onRequestStart">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="SearchRadButton">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="AttachmentRadGridView" />
                <telerik:AjaxUpdatedControl ControlID="AttachmentRecordRadLabel" />
            </UpdatedControls>
        </telerik:AjaxSetting>

        <telerik:AjaxSetting AjaxControlID="AttachmentRadGridView">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="AttachmentRadGridView" LoadingPanelID="gridLoadingPanel"></telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

My GridView Where I The button for download exist:
ASPX
<telerik:GridTemplateColumn HeaderText="Request Download" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
        <asp:ImageButton ID="imgDownload" runat="server" ImageUrl="/images/attachment24.png" CommandName="download_file" Height="22px" Width="22px" ToolTip="Request Download" CommandArgument='<%# Eval("ID") %>' />
    </ItemTemplate>
</telerik:GridTemplateColumn>

CodeBehind:
VB.NET
Protected Sub AttachmentRadGridView_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles AttachmentRadGridView.ItemCommand
    If e.CommandName = "download_file" Then
        Dim ditem As GridDataItem = CType(e.Item, GridDataItem)
        Dim AttachID As Long = CLng(ditem("ID").Text)
        DownloadFileAttachment(AttachID)
    End If
End Sub

Protected Sub DownloadFileAttachment(ByVal FileId As Long)
    'Dim id As Integer = Integer.Parse(TryCast(sender, LinkButton).CommandArgument)
    Dim bytes As Byte()
    Dim fileName As String, contentType As String
    Dim constr As String = dbpath
    Using con As New SqlConnection(constr)
        Using cmd As New SqlCommand()
            cmd.CommandText = "select FileName, ImageData, FileType from FileStore where FileId=@FileId"
            cmd.Parameters.AddWithValue("@FileId", FileId)
            cmd.Connection = con
            con.Open()
            Using sdr As SqlDataReader = cmd.ExecuteReader()
                sdr.Read()
                bytes = DirectCast(sdr("ImageData"), Byte())
                contentType = sdr("FileType").ToString()
                fileName = sdr("FileName").ToString() & "." & contentType
            End Using
            con.Close()
        End Using
    End Using
    
    Dim path As String = MapPath("/Download/" & fileName)
    Response.Clear()
    Response.Buffer = True
    Response.Charset = ""
    Response.Cache.SetCacheability(HttpCacheability.NoCache)
    Response.ContentType = contentType
    Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName)
    Response.BinaryWrite(bytes)
    Response.Flush()
    Response.End()
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

What I have tried:

1- postback=true
2-
JavaScript
function onRequestStart(sender, args) {
    if (args.get_eventTarget().indexOf("imgDownload") >= 0)
        args.set_enableAjax(false);
    }

    args.set_enableAjax(true);
}
Posted
Updated 18-May-20 5:59am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900