Thread: Handles ???
View Single Post
  #1 (permalink)  
Old November 8th, 2015, 02:58 PM
Grodnik Grodnik is offline
Authorized User
Points: 91, Level: 1
Points: 91, Level: 1 Points: 91, Level: 1 Points: 91, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2015
Location: rural Minnesota
Posts: 19
Thanks: 6
Thanked 0 Times in 0 Posts
Default Handles ???

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"
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

                FileUpload1.SaveAs(savePath)
                lblStatus.Text = "File successfully uploaded"
                '               Response.Redirect("default.aspx")
            Else
                lblStatus.Text = "Upload failed - File requires .doc or .docx extension"
            End If
        Else
            lblStatus.Text = "No upload; File not specified"
        End If

    End Sub
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.

Code:
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Response.Write("This is a test")
    End Sub
Why do they execute differently?
Reply With Quote