2013-03-05 5 views
0

나는 시각적 인 개발자 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 


+0

* 왜 * 두 번 실행되는지 이해하기 위해 디버깅을 시도 했습니까? – Blachshma

+0

소스에서 유일한 방법입니까? 두 번째 호출로 인해 이미지를 두 번 이상 저장하는 것처럼 들립니다. –

답변

0

당신은 페이지의로드 이벤트에서 같은 코드가 있습니까? 다시 게시하면 두 이벤트가 모두 실행되므로 수행하면 두 번 실행됩니다.

+0

파일을 삭제하고 다시 만들었으므로 괜찮습니다. – Nita

관련 문제