问题
I am writing an application that requires a user to upload files to the server machine. All user interaction with the user is done via JQuery UI modal popups. I created a test page to see that the AsyncFileUpload control works, and everything works fine on it. I added the AsyncFileUpload to the webform that I need it on, in a modal popup, but for some reason the server side event is never fired. The only difference on this page from the test page is that I send a variable through on the querystring which I, on initial load of the page, store in the viewstate (so it isn't required on future postbacks). Any ideas?
Thanks
回答1:
When you use AsyncFileUpload you must set the right params in the "form" tag, that is placed in your Page or MasterPage:
<form id="form1" runat="server" enctype="multipart/form-data" method="post">
If you don't set the right enctype and method UploadedComplete will never fire, and you won't be able to get FileUpload.FileBytes since FileUpload.HasFile returns true only during UploadedComplete execution.
I suppose that you didn't set the correct enctype on your modal popup.
Besides, prevoius versions of AsyncFileUpload didn't work on Chrome. Actual version (4.1.50731.0) solved the problem.
回答2:
When dealing with AsyncFileUpload Control's Event, store any data in Session state instead of viewstate.
来源:https://stackoverflow.com/questions/1592789/asp-net-ajax-asyncfileupload-control-not-firing-server-side-onuploadcompleted-ev