Thursday, May 24, 2007

asp:FileUpload not posting back?

This is fun.

Didn't really find a whole lot out there on this so I figured I'd post it just in case I ever forget :)
We had a little upload pop-up in an ASP.NET application. We are just using the 'asp:FileUpload' control for this. We have another regular ASP button that has a server-side click event that will perform some validation and then save the file into a database and a few other things. Well someone reported a bug stating that if you just typed in anything (ie 'asdf') then it wouldn't let you know that it was an invalid file. No validation would be performed. We'll I started looking into this and noticed that the button click event wouldn't even post back? It would only post back if you had something that was somewhat valid entered in. (ie. 'c:\bob.txt').
Well here's the reason. This happens only when using IE. This is an IE specific issue. If you try this same thing in FireFox or Opera you'll notice that the post back will be fire off just as expected. IE trys to validate this before calling back. So if you enter something in that is just invalid IE wont even bother posting back, thus you'll never see your lovely button click event ever being called.

Don't believe me. Try it for yourself. Here's a link to a site that already has a sample 'asp:FileUpload' control loaded. Try it in IE and then in some other browser both with valid files and some junk like 'asdf'. You'll notice you only get the postback with the junk data on non-IE browsers.


Steve said...

I ran in to the same problem today. Confound it if I can find a work around. Would be very interested to hear if you find a solution.

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!