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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
masterpassConnect With a Mentor Commented:
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
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
 
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
 
Johny BravoAuthor Commented:
Thanks for the valuable help
0
All Courses

From novice to tech pro — start learning today.