Strange empty square!

Discussion in 'ASP.NET / ASP.NET Core' started by Steve, Mar 11, 2016.

  1. Hello

    I have a Web page that allows a user to upload his files. When the upload has completed, a few lines of text appear that show the name of the file uploaded, its size, and where it has been uploaded to. These lines of text are in a border/box.

    However, when you first go to the upload page - and before doing anything - you can see a small empty box on the form. It looks like this:

    [​IMG]

    The code for the upload file looks like this:

    Code:
    ProtectedSub btnUpload_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnUpload.Click
    
    If MyFileUpload.HasFile Then
    
    Try
    
    MyFileUpload.SaveAs("C:/Uploads/" & MyFileUpload.FileName)
    
    Label5.Text = "File name: " & _
    
    MyFileUpload.PostedFile.FileName & "<br>" & _
    
    "File Size: " & _
    
    MyFileUpload.PostedFile.ContentLength & "<br>" & _
    
    "Content type: " & _
    
    MyFileUpload.PostedFile.ContentType & "<br>" & _
    
    "Location Saved: C:/Uploads/" & MyFileUpload.FileName
    
    Catch ex AsException
    
    Label4.Text = "ERROR: " & ex.Message.ToString()
    
    EndTry
    
    Else
    
    Label3.Text = "You have not specified a file."
    
    Label2.Visible = False
    
    EndIf
    
    EndSub
    and Label5, which displays the details of the uploaded file, look like this in my aspx page:

    Code:
    <asp:LabelID="Label5" runat="server" Text="" CssClass="FileResult"></asp:Label><br/>
    How can I make that empty square disappear, please, until it is complete with file data after the file has been uploaded?

    Many thanks.

    Steve
     
  2. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    I can't think of the code offhand, but the logic would be:

    1) Hide Label5.
    2) Have some code to check that file upload is complete.
    3) Show Label5.
     
    mjp likes this.
  3. Hello Ray

    Many thanks for your reply.

    I have tried this:

    Code:
    Try
    
    MyFileUpload.SaveAs("C:/Uploads/" & MyFileUpload.FileName)
    
    Label5.Text = Visible = False
    
    Label5.Text = "File name: " & _
    
    MyFileUpload.PostedFile.FileName & "<br>" & _
    
    "File Size: " & _
    
    MyFileUpload.PostedFile.ContentLength & "<br>" & _
    
    "Content type: " & _
    
    MyFileUpload.PostedFile.ContentType & "<br>" & _
    
    "Location Saved: C:/Uploads/" & MyFileUpload.FileName
    
    Label5.Text = Visible = True
    
    'Label5.Visible = True
    
    Catch ex AsException
    
    Label4.Text = "ERROR: " & ex.Message.ToString()
    
    EndTry
    but that white square is still there!

    Thank you again.
     
  4. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    Correct me if I'm wrong since I'm not an expert in VB, but I think it should be:

    Code:
    Label5.Visible = False
    Label5.Visible = True
    
    I've never seen a triple assignment statement before.
     
    martino and mjp like this.
  5. Many thanks for that, Ray!

    Enjoy your guitar!
     
    martino and RayH like this.

Share This Page