I would like to display a label and image when someone clicks the submit button to upload a file. I've been tinkering around with progress bars, but none seem to work correctly with the rest of my code. What I though I could do is simply show a label and image when someone clicks the button, however the label and image don't show up until after the upload takes place. I'm assuming this is because the click event for the browse button on a Fileupload control is the same as the button_click event I think. Anyway, below is the code I'm trying to use:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
btnProgress.Visible = False
lblProgress.Visible = False
End Sub
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
'before submitting make sure there is a file
If FileUpload1.HasFile Then
btnProgress.Visible = True
lblProgress.Visible = True
SaveFile(FileUpload1.Poste
dFile)
Else
lblUploadResult.Text = "Your file was not uploaded properly, please try again or contact the webmaster at emailaddresshere."
End If
End Sub
Sub SaveFile(ByVal file As HttpPostedFile)
'Path where file is uploaded
Dim savePath As String = System.Configuration.Confi
gurationMa
nager.AppS
ettings("U
ploadFolde
rHere")
'Get name of client file and then extract extension
Dim extension As String = FileUpload1.FileName
Dim ext As String = System.IO.Path.GetExtensio
n(extensio
n)
'name of file
Dim fileName As String = txtPresNumber.Text & "_" & txtLastName.Text + ext
'Create path and filename to check dups
Dim checkPath As String = savePath + fileName
'temp filename to check dups
Dim tempFileName As String
If (System.IO.File.Exists(che
ckPath)) Then
Dim counter As Integer = 1
While (System.IO.File.Exists(che
ckPath))
tempFileName = counter.ToString() & "_" & fileName
checkPath = savePath + tempFileName
counter = counter + 1
End While
fileName = tempFileName
lblUploadResult.Text = "Thank you very much, your file has been received."
Else
lblUploadResult.Text = "Thank you very much, your file has been received."
End If
'Append Name
savePath += fileName
'Call save as method
FileUpload1.SaveAs(savePat
h)
Start Free Trial