0

我正在使用visual developer 2012,并有一个简单的表单将文件上传到服务器,然后将文件名输入到另一个表中。无论出于何种原因,它都会运行两次并在第二个表中输入两次值:

Protected Sub BtnUploadImg_Click(sender As Object, e As EventArgs) Handles BtnUploadImg.Click
    If IsPostBack Then
        ' Dim CurrentPath As String = Server.MapPath("C:\DSimages\")
        If FileUpLoad1.HasFile = True Then
            Try
                FileUpLoad1.SaveAs("C:\DSimages\" & _
                   FileUpLoad1.FileName)
                Label1.Text = "File name: " & _
                   FileUpLoad1.PostedFile.FileName & "<br>" & _
                   "File Size: " & _
                   FileUpLoad1.PostedFile.ContentLength & " kb<br>" & _
                   "Content type: " & _
                   FileUpLoad1.PostedFile.ContentType
                ImageDataSource.InsertParameters("ImgName").DefaultValue = FileUpLoad1.PostedFile.FileName
            Catch ex As Exception
                Label1.Text = "ERROR: " & ex.Message.ToString()
            End Try
        Else
            Label1.Text = "You have not specified a file."
        End If
    End If

    ImageDataSource.Insert()
    FileUpLoad1.PostedFile.InputStream.Dispose()     

End Sub


4

1 回答 1

0

您在页面加载事件下是否有相同的代码?回发将触发这两个事件,因此如果您这样做,它将运行两次。

于 2013-03-05T16:17:39.517 回答