Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a gridview and a download button for each and every row.
the page objective is to list out all the records related to physical files, and when download button clicked it should download and open the downloaded file. the files are in 'pdf' format.

The page is coded and everything is going fine. I want to rebind the gridview when the file got downloaded. but after download, the rest of the page's execution or lifecycle is not being done.

it seems the issue is with page handlers. I tried searching over the internet, but unfortunately no solution found. I request you experts please help me in this issue.
and my code is like below.

VB
Dim archiveLG() As String = fileName.Split("-")
                Hos.ArchiveLG(archiveLG(0).Substring(1), archiveLG(1).Replace(".pdf", ""))

                grdLGs.DataBind()



VB
Dim outputStream As FileStream = New FileStream((Server.MapPath("../ScannedDoc") + ("\\" + fileName)), FileMode.Create)
                    reqFTP = CType(FtpWebRequest.Create(New Uri(DataDirectory + "InternalDocuments/" + folderName + "/" + fileName)), FtpWebRequest)

                    reqFTP.Method = WebRequestMethods.Ftp.DownloadFile
                    reqFTP.UseBinary = True
                    reqFTP.Credentials = New NetworkCredential(uid, pwd)
                    Dim ftpresponse As FtpWebResponse = CType(reqFTP.GetResponse, FtpWebResponse)

                    Dim ftpStream As Stream = ftpresponse.GetResponseStream
                    Dim cl As Long = ftpresponse.ContentLength
                    Dim bufferSize As Integer = 2048
                    Dim readCount As Integer
                    Dim buffer() As Byte = New Byte((bufferSize) - 1) {}
                    readCount = ftpStream.Read(buffer, 0, bufferSize)

                    While (readCount > 0)
                        outputStream.Write(buffer, 0, readCount)
                        readCount = ftpStream.Read(buffer, 0, bufferSize)

                    End While
                    ftpStream.Close()
                    outputStream.Close()
                    ftpresponse.Close()

                    Dim responseFile As String = Server.MapPath("../ScannedDoc") + ("\\" + fileName)
                    Response.ContentType = "application/pdf"
                    Response.AppendHeader("Content-Disposition", ("attachment; filename=" + fileName))
                    Response.TransmitFile(responseFile)
                    Response.Flush()


Thanks in advance.
Sri
Posted
Updated 6-Jun-13 20:51pm
v2

1 solution

Well,the title of the question should be somewhat different because Page lifecycle doesnt stop in this scenario.

Actually you are trying to click the button that resides in a gridview.So you are trying to catch the click event of that button(As per i understand the question),so refer to below link which describes how to handle buttons inside gridview.

How to: Respond to Button Events in a GridView Control[^]

Get the click event of that button as suggested and perform appropriate operations there.

Regards... :)
 
Share this answer
 
Comments
cyanceenu 7-Jun-13 2:50am    
Good to see a reply.. Yeah... I'm able to click the button and the code associated with the click event is also getting done. but In my code I'm rebinding the gridview, which is not getting done. thats' the issue. :)
Thanks7872 7-Jun-13 2:51am    
I think you are binding grid at Page_load event?Did you?
cyanceenu 7-Jun-13 2:53am    
No please check the improved question here.. I'm binding the grid in the same RowCommand event.
Thanks7872 7-Jun-13 2:56am    
Let me explain it from top to bottom. First in page load event define If(!IsPostBack) and inside that bind your gridview with your required data.Onclick event of that button(Download) again bind gridview with the data you want.Got it?
cyanceenu 7-Jun-13 3:03am    
The same thing I'm doing. The issue is when the file got downloaded the grid is not getting bind. even I tried this line " grdLGs.DataBind() " as last statement.

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