views:

363

answers:

5

I want to upload a file using asp.net so I do not want to post back the page while uploading . How can I do that and is there any way to do it using Ajax .

A: 

An iframe can be placed on your page and can contain an input element, type=file. You can manipulate and submit the iframe form via javascript. You can hide the iframe by setting its CSS style to display:none. This is generally known as the hidden iframe method.

Jeff Meatball Yang
A: 

Use something proven like SWFUpload and save yourself the time of writing your own client code.

cottsak
word of warning: for some reason SWFUpload doesn't work from behind my corporate proxy. http://swfupload.org/forum/generaldiscussion/349
russau
good to keep in mind +1. you should always have a non-flash backup anyway (standard HTML form POST) IMO
cottsak
A: 

here is an article on CodeProject describing how to build Ajax file upload with asp.net.

Here is one that uses jQuery.

TheVillageIdiot
+2  A: 

Make the file upload form target a hidden iframe.

<iframe name="UploadTarget" style="display:none"></iframe>
<form target="UploadTarget" action="postfile" method="post" enctype="multipart/form-data">
<input type="file" name="MyFile">
<input type="submit" name="submit" value="Send me a file">
</form>

The final trick is to add to your response page:

<script type="text/javascript">parent.somecallbackfunction("Here is some data")</script>

To let your parent page ( the one containing the hidden iframe) know that the the file upload has completed.

lambacck