Link to home
Start Free TrialLog in
Avatar of Johny Bravo
Johny Bravo

asked on

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?
Avatar of Umar Topia
Umar Topia
Flag of India image

If you are using UpdatePanel in your page then you need to add the "Submit" button in Triggers to make it work
Avatar of Johny Bravo
Johny Bravo

ASKER

Yes I am using Updatepanel.
Do you mean I should add triggers for all dropdowns and Save button?
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

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.
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
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
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
>>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.
ASKER CERTIFIED SOLUTION
Avatar of masterpass
masterpass
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the valuable help