none
Problems using asp.net control FileUpload RRS feed

  • Question

  • I am building a web page that needs to allow users to select a file to upload. 

    I have never used the file uploader before, but I don't need to actually move the file anywhere, after they select it I read it and write the info to a database.

    I have the "onchange" set to execute a javascript function that calls a subroutine in my vb code that does the work.

    The problem I am having is that when I select a file and click the "Open button" the file uploader .HasFile (in my VB code) is false UNLESS I put a breakpoint on the line before my IF statement. 

    If I do that and then click Continue after selecting the file it works perfectly. If I disable the breakpoint it never selects a file. 

    I should point out that when the breakpoint is active, it gets hit multiple times, even though I only selcted the file and hit "Open" once and the FileUploadComplete is only referenced in that one spot.

    I know this sounds crazy!

    Here is what my code looks like:


    -----------------  ASP.net code


    <script type="text/javascript">

      function FileUploadComp() {

         var AttID = '<%=AttachmentID%>';  //document.getElementByID("FileUpload1");
         __doPostBack('FileUpload1', AttID);

     }

    </script>


      <asp:FileUpload ID="FileUpload1" runat="server" AutoPostBack="true" onchange="FileUploadComp();"/>



    ------------------  VB.net Code

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If Not IsPostBack Then

    ....
            Else   'If Not IsPostBack 

                Dim eventTarget As String
                Dim eventArgument As String

                If (Me.Request("__EVENTTARGET") Is Nothing) Then
                    eventTarget = String.Empty
                Else
                    eventTarget = Me.Request("__EVENTTARGET")
                End If

                If (Me.Request("__EVENTARGUMENT") Is Nothing) Then
                    eventArgument = String.Empty
                Else
                    eventArgument = Me.Request("__EVENTARGUMENT")
                End If


                Dim valuePassed As String = eventArgument

                FileUploadComplete()


            End If   'If Not IsPostBack 
    End Sub




    Sub FileUploadComplete()


    'This is where I put the breakpoint
            debugLine = debugLine + "  100 "

            If FileUpload1.HasFile Then

    .....  this is where the work is done uploading the info from the file

    End Sub
    Thursday, June 13, 2019 5:08 PM

All replies

  • ASP.NET issues can be discussed at the ASP.NET forums.

    http://forums.asp.net/

    Thursday, June 13, 2019 5:19 PM
  • I posted it on this forum since the problem is actually happening in the VB code.
    Thursday, June 13, 2019 6:35 PM
  • I posted it on this forum since the problem is actually happening in the VB code.

    And somehow VB.NET or C# has something to do as to why it's not working? OK, the horse can be lead to the water, but it's up to the horse to take the drink.
    Thursday, June 13, 2019 6:43 PM
  • You really don't need to be so nasty, this is the first time I have worked with asp.net. On your advice I also posted in the ASP.net forum. 
    Thursday, June 13, 2019 6:57 PM
  • You really don't need to be so nasty, this is the first time I have worked with asp.net. On your advice I also posted in the ASP.net forum. 

    You know, I could say the same about you and your opening response. All I did was told you where you should actually post and to the people that would have strongly had the problem before on a file upload to a Web server using an ASP.NET solution that uses C# or VB.NET code.

    This forum here the VB.NET forum is basically a Windows desktop solutions forum dealing with VB.NET, just like the MSDN C# forum is basically a Windows desktop forum. 

    Maybe, your problem is you're using the fake IIS, IIS Express,  and not using local IIS the real Web server on your machine where a file upload actally meant something and was actually working in a real situation.

    https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-enable-debugging-for-aspnet-applications?view=vs-2017

    The optimal approach is ASP.NET issues should be discussed in the ASP.NET forums, regardless of what server-side language C# or VB.NET is being used, becuase developers in the forums know both languages.

    Thursday, June 13, 2019 7:49 PM