Solved

Update Panel File Upload

Posted on 2007-04-09
6
746 Views
Last Modified: 2008-02-01
Hi,

Has anyone been able to work a fiel upload so that it works inside an Update Panel?  Even setting PostbackTriggers I cannot get this to work.

Andrew
0
Comment
Question by:REA_ANDREW
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 18874956
Nope, I tried for a while and could never figure it out.

A popular was is to post the file to a hidden frame.  There are a few Asp.net examples i found when filtering through google.
0
 
LVL 3

Expert Comment

by:ieciep
ID: 18875140
As many people have noticed in their AJAX-enabled pages, file uploads do not work when doing an async postback. To my knowledge there's no way to support this scenario due to the browser's security restrictions. To understand why the upload doesn't work it's important to understand how async postbacks are performed and how that's different from how the browser performs a regular postback.

When the browser performs a regular postback it has the benefit of being actual code with no security restrictions running on the client computer. When you submit a form it creates a web request with all the form fields. When it encounters an <input type="file"> it examines the file the user chose, reads it from disk, and adds it to the web request.

When the AJAX JavaScript code is running in the browser it can do the first part about creating a request with all the form fields. However, when it gets to <input type="file"> fields it doesn't have the necessary security permissions to read those files from disk. Imagine what would happen it it could read those files: You could create a page that when visited will upload the user's c:\passwords.txt to a remote server! And we all know that every user has a file called passwords.txt on their C: drive. I bet just now you renamed it so my evil code couldn't run :)

 
So what's the workaround? Well, quite simply, the workaround is to do anything that doesn't involve a file upload during an async postback. Here are some solutions:

Have a dedicated "Upload" button that does a regular postback instead of an async postback. You can achieve this using several techniques: Have the button be outside all UpdatePanels; have the button be the target of an UpdatePanel's PostBackTrigger; or call ScriptManager.RegisterPostBackControl() on it.
Have a dedicated file upload page that doesn't have any UpdatePanels. Many web sites already do this anyway.
And now you might wonder, "why don't ASP.NET AJAX and the UpdatePanel handle this better?" We did give this a fair bit of thought and we decided that doing nothing was the best solution. One option we had was to throw some error from JavaScript if we detected any filled out <input type="file"> tags. But what if you wanted to do an async postback that had nothing to do with the file upload? Or perhaps only detect file uploads in certain regions of the document? That would involve even more expensive DOM tree walks that are already causing some performance degradation with UpdatePanels.

In conclusion, if you want a secure browser, you're not going to get file upload functionality from UpdatePanels. If you don't want a secure browser, please get your head checked. If you want to do file uploads, just use one of the two solutions I provided.

0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 18875161
ieciep, just out of interest, have you pasted Eilon Lipton's Blog into here?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:ieciep
ID: 18875173
yes
0
 
LVL 12

Accepted Solution

by:
UnexplainedWays earned 500 total points
ID: 18875186

http://www.codeproject.com/useritems/AJAXUpload.asp
I tried this one, but there was javascript security issues.

This site has a nice upload, i was going to view the source and find out how they did it:
http://www.sharebig.com/

Luckly, work purchased these controls that included this one so i didn't need to write it. However, it does ajax the upload, it sill posts back right at the end.
http://www.telerik.com/products/aspnet/controls/upload/overview.aspx

Also, Googled the first para:
http://weblogs.asp.net/leftslipper/archive/2007/03/30/why-don-t-file-uploads-work-during-async-postbacks.aspx
0
 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 18875203
Thanks :]

Good luck with it, just remember there are quite a few out there you can purchase.  So weight up the cost of your time to build your own or to purchase.  Cause the one i have is per developer.  So share the cost over the next few clients ;)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Service with UDP 2 28
Converting C# Objects into JSON file 7 39
Hovering effect 9 29
JavaScript error 1 33
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now