File upload - button only, with postback????

Hi.

I'm creating a page where users can upload files using the .Net 2 FileUpload component (hopefully!!)

I understand that this is similar to the input type of 'file', and that you're supposed to select a file, and then have a seperate button for submitting and therefore uploading, but I find this particularly ugly.

I simply want a browse button that pops up the FileUpload's 'browse' dialog, and then uploads the file if the user clicks 'okay', therefore allowing me to handle the server side stuff and save the file etc..

The closest I have got to this is a button that clicks a 'hidden' FileUpload control, and then does a postback via JavaScript, but this does not work - you get an 'access denied' error, caused by the FileUpload not having a file.

If you get what I'm asking for, can someone please let me know if this is possible, without having to code the upload myself.  (I've done this before when coding with pure ASP, not .Net, and would rather not have to do it, especially since the FileUpload component already does most of what I need!!!)

Thanks in advance,

John.
LVL 6
JaymolAsked:
Who is Participating?
 
JaymolConnect With a Mentor Author Commented:
Okay, so this turned out to be an absolute doddle (when I knew how ;o)  I'm posting the answer so that anyone searching and turning up here will get what they need.

I simply added the onchange event handler to the asp declaration of the fileupload component declaration (in the aspx), like so..

<asp:FileUpload ID="fileUpload" runat="server" onload="fileUpload_Load" Visible="True" onchange="submit()" />

Now I just need to remove the textbox in a satisfactory manner.  Setting the width to 0px in the style attribute nearly does it.  I just need to persevere.

0
 
zkeownCommented:
I've not used this custom control, but have heard good things.  It's a customized FileUpload with an AutoPostBack event, which should handle what you're after.

http://www.metabuilders.com/Tools/FileUpload.aspx
0
 
JaymolAuthor Commented:
Thanks, but I don't want to use 3rd party controls - I want this coded myself.

Incidentally, on a funny note, the link you gave me points to the controls that I'm currently replacing!!!

Thanks again.
0
All Courses

From novice to tech pro — start learning today.