I need help understanding something about how handles work.
I created a simple demo version of an upload. The page is just the file upload control, a button, and a label. The code"
Dim savePath As String = "C:\UploadedDocs\"
Protected Sub btnUpload_Click(sender As Object, e As EventArgs) Handles btnUpload.Click
If (FileUpload1.HasFile) Then
Dim filename As String = Server.HtmlEncode(FileUpload1.FileName)
Dim extension As String = System.IO.Path.GetExtension(filename)
If (extension = ".doc") Or (extension = ".docx") Then
savePath += filename
lblStatus.Text = "File successfully uploaded"
lblStatus.Text = "Upload failed - File requires .doc or .docx extension"
lblStatus.Text = "No upload; File not specified"
It executes twice and I get 2 files uploaded in savepath, test1.docx and test1.docxtest1.docx
If I remove the Handles btnUpload.Click, it executes just once
However, with most btn click events, the subroutine is executed just once.
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Response.Write("This is a test")
Why do they execute differently?