
04-14-2012, 06:52 AM
|
|
Regular
|
|
Join Date: Sep 2007
Posts: 50
|
|
Download button
|
Hi,
In my project, I've created a download button.
This button shall perform 3tasks:
1. Change label text
2. Download file
3. Make the button invisible
The following code changes the label text and make the button invisible:
Code:
Protected Sub btnDownload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDownload.Click
lblDownload.Text = "<h3>Thank you for downloading </h3>"
btnDownload.Visible = False
End Sub
When I add a piece of code that handles the file download, the label text is not changed and button remains visible.
Here is the code:
Code:
Protected Sub btnDownload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDownload.Click
Dim URL As String = "~/myfile.exe"
Dim fileInfo As FileInfo = New FileInfo(Server.MapPath(URL))
If fileInfo.Exists Then
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name)
Response.AddHeader("Content-Length", fileInfo.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.Flush()
Response.WriteFile(fileInfo.FullName)
End If
lblDownload.Text = "<h3>Thank you for downloading</h3>"
btnDownload.Visible = False
End Sub
File downloading cancels other operations.
Do you have any ideas?
|
|