Marco
Marco

Reputation: 1272

Upload files without full page postback

The Plan

  1. I need to upload a file without causing a full page refresh.
  2. The uploaded files should be stored in a temporary place (session or cookies).
  3. I will only save the files in the server, if the user sucessfully fills all the form fields.

Note: This is one of the slides of a jQuery slider. So a full refresh would ruin the user experience.


The Problem

If I place a Fileuploader Control inside a AJAX Update Panel, I wont be able to acess the file on the server side.

Note:From what I have found so far, this happens due to safety reasons.

Can't be done without co-operating binaries being installed on the client. There is no safe mechanism for an AJAX framework to read the contents of a file and therefore be able to send it to the server. The browser supports that only as a multipart form post from a file input box.


The Questions

  1. When storing the files in a temporary location, should I use session or cookies? (what if the user has cookies disabled?)
  2. If preventing a postback, really is against the standarts of user safety. Will it harm my website reputation? (regarding SEO and such)
  3. Which road to take?
    • C# ASP.Net with AJAX? (is there a workarround?)
    • C# ASP.Net + AJAX Control Toolkit? Does it helps? (using the AsyncFileUpload control)
    • C# ASP.Net + jQuery Control? (won't I have problems fetching the data from the JavaScript?)
    • C# ASP.Net + iFrame? (not the most elegant solution)

Upvotes: 0

Views: 1634

Answers (1)

Guffa
Guffa

Reputation: 700312

  1. The total amount of cookies that you can use is limited to a few kilobytes, so that's not a viable option to store a file. So sessions would be the only remaining. Consider also to save the file in the file system and remove it if it's not going to be used, as storing files in memory (session) will limit how many users you can handle at once.

  2. No, for functions like uploading files you don't have to worry about that. Search engines doesn't try to use such functions when scanning the page.

You can use an AJAX upload in browsers that support direct file access, but there is no way around doing a post if you need to support all browsers. However, the post doesn't have to end up loading a new page, you can put a form in an iframe, or point the target of a form to an iframe.

Upvotes: 2

Related Questions