Connecting Tech Pros Worldwide Help | Site Map

Asynchronous File Upload

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#1: Sep 16 '09
I'm attempting to upload a file asynchronously to the server by using an IFrame.

I have an Asp.NET FileUpload control on the page (which renders as an <input type="file> HTML element) and a submit button along with an IFrame.

I am attempting to redirect the form's target into the IFrame.

I have the following JavaScript function which should redirect the form's action into an Iframe on the page:
Expand|Select|Wrap|Line Numbers
  1. function redirectFormAction(iframeTargetID) {
  2.     var theForm = document.forms['theFormsID'];
  3.     theForm.target = iframeTargetID;
  4. }
This method is called on the button's onclick event:
Expand|Select|Wrap|Line Numbers
  1. <input id="fup" type="file" style="width: 222px;" name="fup"/>
  2. <input id="upload" type="submit" style="width: 222px;" onclick="ChangeHasOccurred(); AllowPostback('xyz'); redirectFormAction('ctl00_theiframe');" value="Preview" name="upload"/>
  3. <iframe id="ctl00_theiframe" src="#" name="ctl00_theiframe">
  4. </iframe>
The page form is still submitting in the window (not the iframe)...what am I doing wrong?

-Frinny
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Sep 16 '09

re: Asynchronous File Upload


See the code for this. Should give some ideas.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#3: Sep 16 '09

re: Asynchronous File Upload


I'm actually using that article (along with a few others) as a reference right now.

I didn't want to create an Object that is going to do something during the form's onsubmit either (because it should just happen when the button's clicked).

And instead of dynamically creating the iframe I've just added it to the page to keep things simple...

I didn't really see the point of creating an Object to do all of that when I could keep things much simpler..

However, I haven't tried "f.setAttribute('target', name);"
[edit]
The setAttribute() method did not make any difference.
It still isn't working, the page is still isn't being submitted using the iframe.
[/edit]
Reply


Similar JavaScript / Ajax / DHTML bytes