This project is read-only.


AsyncFileUpload causes ViewState to lose the content


Im'using the component inside a UpdatePanel, the components are part of a CompositeControl.
I have others composite controls like this one, but no other using AsyncFileUploa, all the controls use the viewstate variables to get and set properties, it's work perfect, but when i use the AsyncFileUploadState inside the control, the ViewSate variables don't keep the values, it's all "erased".

Can someone help me to figure out what is hepping?


file attachments

Closed May 1, 2011 at 9:19 PM by Superexpert
This is the expected behavior of the AsyncFileUpload control.


rgccxning wrote Jan 15, 2011 at 11:26 AM

same question....
i have to use session instead

agwizard wrote Feb 17, 2011 at 11:48 AM

The AsyncFileUpload control severely corrupts the normal page life cycle in two important ways when a post-back is generated as the result of a file being uploaded. Firstly, the UploadedComplete event is raised after OnPreRender for the page - events should be raised before OnPreRender is called. Secondly, after the event has been raised the remainder of the page life cycle is not executed - SaveViewState is not called and Render is not called. This means that the results of the upload cannot be saved in ViewState, and the page cannot be updated with the results of the upload.

This can easily be demonstrated on a simple page containing nothing but a ScriptManager and an AsyncFileUpload.

Workaround: the AsyncFileUpload control saves its state after upload through to the next post-back (but not subsequent post-backs). So one possible workaround is to check the HasFile property of the control in every post-back of the page (in OnLoad), and act upon the upload if HasFile is true. This does mean, however, that the upload is not acted on until the next post-back.

Superexpert wrote Apr 26, 2011 at 4:52 AM

We are investigating this issue.

Superexpert wrote May 1, 2011 at 9:18 PM

This is the expected behavior of the AsyncFileUpload control. If you attempt to set a viewstate variable in the UploadedComplete() handler then the viewstate variable will not be preserved. The AsyncFileUpload control performs a secret postback to itself when you perform an Asynchronous upload. If the UploadedComplete() method modifies viewstate then it changes the viewstate hidden input field in the instance of the page requested with the secret post and not the original page. Therefore, changes to viewstate are not preserved.

The attached Visual Studio project illustrates this behavior. One item is added to viewstate by the page and one item is added to viewstate in the UploadedComplete() event handler. The item added by the page persists across postbacks. The item added in the UploadedComplete() event handler does not persist because the UploadedComplete() handler is being called in a separate page instance.

TTSoft wrote Dec 14, 2012 at 7:40 AM

session variables are cleared as viewstates

so what?