UpdateProgress creates problems for FileUpload

R

Radu

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
simple:

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

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

I have added cmdDoNothing just to test. It has the "complicated code"
System.Threading.Thread.Sleep(5000)
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

Note:
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
so:
UpdatePanelFileUpload.Update()
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.
Alex
 
P

Pete Hurst

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

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.

Pete
 

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

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top