locked
AsyncFileUpload uploads twice RRS feed

  • Question

  • User1650764034 posted

    Hi,

    I have a working AsyncFileUpload and the AsyncFileUpload_UploadedComplete function gets called and then I save the file with a filename from a TextBox on the same page.

    This Textbox is also used in conjunction with a search button to look for already uploaded files.

    So after an upload, when I change the filename in the TextBox and press the button the previously uploaded file gets uploaded again with the new filename because AsyncFileUpload_UploadedComplete fires again on postback.

    How can I prevent this from happening?

    Monday, November 18, 2013 9:13 AM

Answers

  • User1650764034 posted

    Finally found a solution:

    function clearContents() {
                var span = $get("<%=AsyncFileUpload1.ClientID%>");
                var txts = span.getElementsByTagName("input");
                for (var i = 0; i < txts.length; i++) {
                    if (txts[i].type == "text") {
                        txts[i].value = "";
                    }
                    if (txts[i].type == "file") {
                        txts[i].value = "";
                    }
                }
            }

    Had to clear the file value also.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 19, 2013 5:37 AM

All replies

  • User555306248 posted

    clear AsyncFileUpload - http://forums.asp.net/t/1477043.aspx

    Monday, November 18, 2013 10:27 PM
  • User1650764034 posted

    Thanks!

    I tried it and it did not work, here is what happens.

    1) I enter "1" in the textbox and click search.

    result: If file one is present it tells me that, else it says not present on the page.

    2) I use the upload control to upload a file with filename "1".

    result: File gets saved on the server and uploadComplete(sender) function is called which changes text on page to upload successful. It now also calls clearContents() function with AsyncFileUpload client ID.

    3) I enter "2" in the textbox and click search.

    result: The file I uploaded in step 2 gets uploaded again and is saved as file "2" on the server.

    
    

    Tuesday, November 19, 2013 4:01 AM
  • User1650764034 posted

    Finally found a solution:

    function clearContents() {
                var span = $get("<%=AsyncFileUpload1.ClientID%>");
                var txts = span.getElementsByTagName("input");
                for (var i = 0; i < txts.length; i++) {
                    if (txts[i].type == "text") {
                        txts[i].value = "";
                    }
                    if (txts[i].type == "file") {
                        txts[i].value = "";
                    }
                }
            }

    Had to clear the file value also.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 19, 2013 5:37 AM
  • User1650764034 posted

    Hi,

    I just found out that this only works with Internet Explorer 11 and is still uploads twice on Internet Explorer 10!

    Tuesday, November 19, 2013 9:09 AM