Solved

Using AJAX.NET how do you clear an uploadfile control?

Posted on 2011-02-15
9
1,303 Views
Last Modified: 2012-06-27
I have a regular upload file control inside an AJAX.NET updatepanel.  If I use it to upload a file once, its no problem; however, if i hit the submit button again, even though the text box is clear, it is still attached to the previous file uploaded.

How do I clear that so that I may use the uploadfile control freshly?
0
Comment
Question by:RichardRiga
  • 5
  • 2
  • 2
9 Comments
 
LVL 16

Accepted Solution

by:
Kamal Khaleefa earned 250 total points
Comment Utility
0
 
LVL 1

Author Comment

by:RichardRiga
Comment Utility
That's a neat article but how do I call a javascript function after the .NET webservice code has completed its work?
0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
Comment Utility
regarding to Ur  question
but a JavaScript function to see if the file upload is empty

 var FileUpload1="<%=FileUpload1.ClientID %>"
function CheckForTestFile()
   {
        var file = document.getElementById(FileUpload1);
        var fileName=file.value;        
        //Checking for file browsed or not
        if (Trim(fileName) =='' )
        {
            alert("Please select a file to upload!!!");
            file.focus();
            return false;
        }
 }
and on ur button
add this

 <asp:Button ID="btnUpload" runat="server"  OnClientClick="if(CheckForTestFile()){return true}else{return false}"
                                                  text="Upload File" TabIndex="50" EnableViewState="False" />
                                           
0
 
LVL 1

Author Comment

by:RichardRiga
Comment Utility
These methods don't seem to work still.  I have inserted them into the proper places and they are being executed; however, the fileupload control still reports that it has contents when trying to upload a blank file'
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:RichardRiga
Comment Utility
My apologies!!  I completely forgot to mention that I wasn't using an ASP:FileUpload control.  I'm using the AsyncFileUpload control from the AjaxToolkit.  I'm not sure it makes a difference in your answers;however, I should have added that.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 250 total points
Comment Utility
>however, the fileupload control still reports that it has contents when trying to upload a blank file'
Do you mean you are uploading a 0 byte file?
0
 
LVL 1

Author Comment

by:RichardRiga
Comment Utility
Here is what happens:

1.  I use the control to upload a file.  That works, no problem.  
     At this point the control's field resets itself to appear empty.
     Since the field is empty, at this point, if I hit the submit button again, the property fuFileUpload.HasFile should be False.  But its not.  It returns true.

2.  So i use a script:
            function clearContents() {
                 var AsyncFileUpload = $get("<%=fuFileUpload.ClientID%>");
                 var txts = AsyncFileUpload.getElementsByTagName("input");
                 for (var i = 0; i < txts.length; i++) {
                     if (txts[i].type == "text") {
                         txts[i].value = "";
                         txts[i].style.backgroundColor = "white";
                     }
                 }
             }

and call on that script when the file is uploaded with:
<cc1:AsyncFileUpload ID="fuFileUpload" runat="server" OnClientUploadComplete="<%UploadComplete() %>" />

Codebehind has:
    Public Sub CallUploadComplete()
        ClientScript.RegisterStartupScript(Me.GetType(), "removeDoc", "ClearContents()", True)
    End Sub

Something isn't right.  Can anyone fix those three snippets of code to make it work?  I beg!  
And thanks.

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
What does the

IsNothing(fuFileUpload.PostedFile)

return?
0
 
LVL 1

Author Closing Comment

by:RichardRiga
Comment Utility
Project was scrapped.  Apologies for the waste of time, but thank you for being respondent
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now