0

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 .

Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
Sufian Alali
  • 1,459
  • 2
  • 12
  • 9

3 Answers3

3

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
  • 9,768
  • 3
  • 34
  • 46
0

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
  • 37,839
  • 27
  • 91
  • 125
0

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

Matt Kocaj
  • 11,278
  • 6
  • 51
  • 79
  • 1
    word of warning: for some reason SWFUpload doesn't work from behind my corporate proxy. http://swfupload.org/forum/generaldiscussion/349 – russau Jun 10 '09 at 04:35
  • good to keep in mind +1. you should always have a non-flash backup anyway (standard HTML form POST) IMO – Matt Kocaj Jun 10 '09 at 04:44