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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
JaymolAuthor 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.