2010-10-09 81 views
0

你好,我有下面的代碼來上傳我的應用程序的圖片。我想爲此代碼添加一行或多行代碼,以顯示成功消息,如「圖片已成功上傳」在asp.net上傳照片

我知道我需要添加標籤控件來顯示消息,但我不知道如何去。這裏是代碼:

Imports System.Data 
Imports System.IO 
Imports System.Data.SqlClient 

Partial Class PhotoAdmin_Default 
    Inherits System.Web.UI.Page 


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
     UserIdValue.Text = Membership.GetUser().ProviderUserKey.ToString() 
     cannotUploadImageMessage.Visible = False 

    End Sub 


    Protected Sub dvPictureInsert_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles dvPictureInsert.ItemInserted 
     'If the record was successfully inserted, save the picture 
     If e.AffectedRows > 0 Then 
      'Determine the maximum pictureID for this user 
      Dim results As DataView = 
       CType(maxPictureIDDataSource.Select(DataSourceSelectArguments.Empty), 
        DataView) 

      Dim pictureIDJustAdded As Integer = CType(results(0)(0), Integer) 

      'Reference the FileUpload control 
      Dim imageUpload As FileUpload = 
       CType(dvPictureInsert.FindControl("imageUpload"), FileUpload) 

      If imageUpload.HasFile Then 
       Dim baseDirectory As String = Server.MapPath("~/UploadedImages/") 

       imageUpload.SaveAs(baseDirectory & pictureIDJustAdded & ".jpg") 
      End If 

     End If 
    End Sub 



    Protected Sub dvPictureInsert_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvPictureInsert.ItemInserting 
     Dim cancelInsert As Boolean = False 


     Dim imageUpload As FileUpload = 
      CType(dvPictureInsert.FindControl("imageUpload"), FileUpload) 

     If Not imageUpload.HasFile Then 
      cancelInsert = True 
     Else 
      If Not imageUpload.FileName.ToUpper().EndsWith(".JPG") Then 
       cancelInsert = True 'Invalid image file! 

      End If 
     End If 

     If cancelInsert Then 
      e.Cancel = True 
      cannotUploadImageMessage.Visible = True 
     End If 

     'Set the UserId value to the currently logged on user's ID 
     e.Values("UserId") = Membership.GetUser().ProviderUserKey 

     'Set the UploadedOn value to the current date/time 
     e.Values("UploadedOn") = DateTime.Now 
    End Sub 

    Protected Sub gvPictures_RowDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles gvPictures.RowDeleted 
     Dim baseDirectory As String = Server.MapPath("~/UploadedImages/") 
     Dim fileName As String = baseDirectory & 
      e.Keys("PictureID") & ".jpg" 
     File.Delete(fileName) 
    End Sub 
+0

您好喬希可以請你幫我這個東西。我有幾個問題要問,但即時通訊類新的 – onfire4JesusCollins 2010-10-09 03:33:45

+0

謝謝日期/時間已更新。你真是一件幸事。你能幫助我:我希望上傳的照片顯示一個成功的消息,如「圖片已成功上傳。你能幫我嗎? – onfire4JesusCollins 2010-10-09 04:50:37

回答