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

Download link in grid / refresh different grid

1 Answer 54 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
MikeK asked on 11 Oct 2010, 07:47 PM
I believe my problem is with the firing of events for the grid, but I can't figure out how to make it work the way I need to.

I have a grid (grdDocumentList) with a download link for each row. Clicking on this link fires the ItemCommand event, where I build the path to the selection, stream the object to the user, then log this action in my database. I then need to fire a refresh on a different grid (grdMeetingList). I can't get the refresh to fire since the postback already occurred BEFORE the user got the file.

How do I get this first grid to refresh?

Example1.png shows my form and how it is supposed to work. The left grid shows all meetings, and the binding will display a yellow page icon if the user has documents remaining to download. They click View, the right grid rebinds, and as they click the Download link it should refresh the first grid. If they've downloaded all of the documents (whether it fails or not), the yellow page icon disappears. It's not firing due to the postback firing first.

Here's my code for the second grid:

Protected Sub grdDocumentList_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdDocumentList.ItemCommand
    If e.CommandName = "Download" Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim FileName As String = item("FileDownload").Text
        Dim MeetingTopicSid As Integer = item("Meeting_TOPIC_SID").Text
        Dim TargetFile As String = FileName
        Dim file As System.IO.FileInfo = New System.IO.FileInfo(TargetFile) '-- if the file exists on the server
        If file.Exists Then 'set appropriate headers
            Dim liveStream As FileStream = New FileStream(TargetFile, FileMode.Open, FileAccess.Read)
            Dim buffer(CType(liveStream.Length, Integer)) As Byte
            liveStream.Read(buffer, 0, CType(liveStream.Length, Integer))
            Response.ContentType = "application/octet-stream"
            Response.AddHeader("Content-Length", buffer.Length.ToString)
            Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name)
            'Log User Download
            SqlHelper.ExecuteNonQuery(ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString").ConnectionString, "usp_InsertMEETING_TOPIC_DOWNLOAD_LOG", Session.Item("gbUserSid"), MeetingTopicSid, DateTime.Now)
            'Rebind Grid
        End If
    End If
End Sub

1 Answer, 1 is accepted

Sort by
Iana Tsolova
Telerik team
answered on 15 Oct 2010, 08:06 AM
Hi MikeK,

I am not sure if the desired functionality can be achieved. Because when you download a file, the response from the server is that file, and no response is send back to the original page.
You can try first refreshing the grid and then initiating new request for downloading the file.

the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Asked by
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question