UpdateProgress creates problems for FileUpload



Hi. The user uploads an Excel file and then, on the "NEXT PAGE" button
of my page I process that file (validation, loading into a database,
etc). Unfortunately, for a number of reasons, this process takes
almost 10 seconds. So I wanted to show a "Processing" message of some
kind to the user. I am trying to use an "UpdateProgress" control. All
should work well, but the problem is that wnehever I put the "NEXT
PAGE" button inside an UpdatePanel, the code
strFileName = inputFile.PostedFile.FileName
gives a "Object reference not set to an instance of an object" error.
I comment out the UpdatePanel, all's well again, except that, of
course, I don't see the "busy" message anymore. The html is very

<asp:UpdateProgress ID="updProgress"
AssociatedUpdatePanelID="UpdatePanelUploadFile" runat="server">
<img alt="progress" src="images/progress.gif" align="middle"/>

<asp:UpdatePanel ID="UpdatePanelNext" runat="server">
Text="Next Page"
<asp:Button ID="cmdDoNothing" Text="Waste time" runat="server"
OnClick="cmdDoNothing_Click" />

I have added cmdDoNothing just to test. It has the "complicated code"
and it works great - for 5 seconds I can see some wheels spinning.

However, when I click on cmdNextPage, the line
strFileName = inputFile.PostedFile.FileName
in the code-behind fails with the error:
Object reference not set to an instance of an object

I thought that cmdNextPage posts back to the server, but the server
does not know yet about the FileUpload's value because when clicking
the cmdNextPage button, it being in an UpdatePanel, only that
UpdatePanel, "UpdatePanelNext", will have been posted back, not the
whole page, and the FileUpload does not belong to the same
UpdatePanel. So I have tried to put the UploadFile control inside
another UpdatePanel, say "UpdatePanelFileUpload", and to call it like
strFileName = inputFile.PostedFile.FileName
in the hope that now the server will know about the new status of the
"inputFile" control. But it did not work. It still says "Object
reference not set to an instance of an object"...

I cannot extend the UpdatePanel "UpdatePanelNext" all the way up to
"inputFile", because the page is complex, and contains some other
update panels and some other "heavy" controls inside them.

How could I solve this problem ? Thank you very much.



Pete Hurst

Radu said:
How could I solve this problem ? Thank you very much.

The problem is very simply that files cannot be posted using AJAX. There is
just no way for Javascript to read in the binary data and send it with the
XmlHttpRequest - for security purposes as much as anything. Any time you see
an AJAX-like file upload, there is actually some trickery either with a
hidden IFrame or with Flash/Silverlight to make it work.

I ended up writing my own Silverlight component to perform this task. This
also allowed me to display a proper progress bar. If you search Google there
are plenty such components already in existence out there.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question