AsyncFileUpload loses file

Hi I am using AsyncFileUpload control to upload images of Employees.
The employee information form has various fields including this.I have some dropdowns on the form which causes postback,
but when postback occurs, AsyncFileUpload loses the selected file and it is blank.
What can be done?
LVL 8
Johny BravoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Umar Topia.Net Full Stack DeveloperCommented:
If you are using UpdatePanel in your page then you need to add the "Submit" button in Triggers to make it work
0
Johny BravoAuthor Commented:
Yes I am using Updatepanel.
Do you mean I should add triggers for all dropdowns and Save button?
0
masterpassCommented:
If you are using the AsyncFileupload, no need to add a postback trigger ...

Working : The asyncfileupload is diff from other file upload control.... It does not require a postback .. The moment you select a file to the AsyncFileupload it starts uploading the file. the only thing you have to do is write an handler for the UploadedComplete ...

Just see this link

http://www.asp.net/%28S%28fu2l2uzphr2u3u45q2dnez55%29%29/ajax/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Johny BravoAuthor Commented:

I think you are talking abt this event.
protected void AsyncFileUpload1_UploadedComplete(object sender,

               AjaxControlToolkit.AsyncFileUploadEventArgs e)

{

     if (AsyncFileUpload1.HasFile)

     {

         AsyncFileUpload1.SaveAs(Server.MapPath("~/Uploads/" +

         Path.GetFileName(e.filename)));

     }

}
-----------------------------------------
well I am not uploading the file as soon as it is selected.
After selecting the image,user still needs to enter more details and then he will click on the Save button to save the form.
0
masterpassCommented:
well I am not uploading the file as soon as it is selected -----------> you don't have to do that. it is built in to do that ... see this link

http://www.codeproject.com/KB/ajax/AsyncFileUpload.aspx ( see AsyncFileUpload Control Features -- disadvantages)

So as soon as the file is selected it will start upload asynchronously  ... If you are having the code it will be saved ... Now since the file is uploaded you don't have to save it again while the user clicks save .. you can save all others but leave this one
0
Johny BravoAuthor Commented:
Am I lost somewhere?

I am not using this event AsyncFileUpload1_UploadedComplete
and On my Save Nutton CLick I am using AsyncFileUpload1.SaveAs to save the file.

After user selects the file and goes on with filling form,when he selects dropdown that causes postback,the selected file is lcleared from the control
0
masterpassCommented:
You will need to use the event AsyncFileUpload1_UploadedComplete .. I hope by now you must be convinced that file upload will start as soon as the user selects a file.

In the AsyncFileUpload1_UploadedComplete you will need to save the file to the folder and get the filename/path to a viewstate or session

 then finally when you are updating the DB just send the filename from the viewstate or session

NB: For the in between postbacks the selected file WILL be cleared from the control
0
Johny BravoAuthor Commented:
>>NB: For the in between postbacks the selected file WILL be cleared from the control

Can't I have the file still in the Upload control in between postback,as the user may be confused.
Further it may happen that,while saving form data there may be an error or user may leave the page.So in such cases still the image will be uploaded,which is not desired.
0
masterpassCommented:
I don't think so .. as you cannot set this implicitly .. So as a user friendliness you can show the Async Fileupload in a modal pop up ... when user clicks on a link open the modal pop up and when the upload is complete close the modal ... this way you can avoid user confusion

see this links for the client side events such as uploadComplete

http://www.asp.net/ajaxLibrary/HOW%20TO%20Use%20the%20AsyncFileUpload%20Control.ashx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Johny BravoAuthor Commented:
Thanks for the valuable help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.