views:

793

answers:

2

Hi all,

How to upload an image when fileupload is under updatepanel?

I have a button say "upload" inside that update panel.

When I click that button inside the button click event I got the fileupload hasfile=false. Please suggest if there is any way to upload image file when fileupload control is inside update panel and the button is making asyncpostback.

Thanks in advance.

+1  A: 

It is not possible. For security reasons, the browser does not allow javascript to upload files.

There are two normal workarounds for this problem:

  • Perform the upload in an iFrame
  • Use a flash plugin for uploading

I recently applied this tool to upload files asynchronously in my web page, and it works beatifully: http://valums.com/ajax-upload/ It creates an iFrame for you automatically, and posts the frame and and sends the resulting html (or json object) to an event handler. My page that receives the uploaded file, returns a json object describing the file, e.g. filename and a unique id, so that I can link the data that is posted on the main page to the uploaded file.

For security, I store the credentials of the user uploading the file, so when the form is posted I can validate that the user that posts the form is indeed the user that uploaded the file.

Pete