p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4.5 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=710)
-   -   Handles ??? (http://p2p.wrox.com/showthread.php?t=95210)

Grodnik November 8th, 2015 02:58 PM

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"

    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"
                '              Response.Redirect("default.aspx")
                lblStatus.Text = "Upload failed - File requires .doc or .docx extension"
            End If
            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.


    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?

Imar November 8th, 2015 04:53 PM

Sounds like you have an additional OnClick handler set up in the Markup section of the page.



All times are GMT -4. The time now is 04:39 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.