Reputation: 497
This is driving me nuts. On my page I have several FileUploads
that are created on the code behind and attached to a few different divs. Once the user selects a file, they click ok, it should be added to the database and redirected somewhere else. What's weird is that when I check the postedFile
property, it's always null. I've tried so many things I'm out of ideas. I've set this Page.Form.Attributes.Add("enctype", "multipart/form-data");
on page load when it's not post back. I've set the same property straight onto the master page form. Tried checking request.files
and it's empty. Fileuploads are not inside en UpdatePanel
. I'm aware that the file is lost on postback, but the only postback that's happening is caused by that same button they have to click to upload on the database. I'd post my code, but it's nothing special.
Server side:
LinkedList<FileUpload> _docs = new LinkedList<FileUpload>();
var files = Request.Files;
foreach (var d in docs)
{
_docs.AddLast((FileUpload)docsDiv.FindControl(d.ID));
}
docs
is a list that contains all of the fileupload created. I only use it as a look up. _docs
is the one that contains the actual fileUploads with selected file. When I debug _docs I see that every item has postedfile null and has file false even thought the only post back was that ok button. When I debug files
it's also empty.
Side note: there's much more coding on my side, but its pretty much different kinds of validations, querys and re-population of textboxes on edit. This part is crucial and it;s only done in one places and what I've posted is step one. Once it's fixed Everything else won't give me any problems.
Please help and thank you
Upvotes: 0
Views: 2750
Reputation: 7668
To use an FileUpload
Control with UpdatePanel
, you can use the trick described here: http://www.codeproject.com/Articles/16945/Simple-AJAX-File-Upload
Working for me...
Upvotes: 1
Reputation: 497
Noticed I had some updatepanels, even though there weren't any fileUploads nested in any of them, still caused problems. Replaced all updatePanels with Page.DataBind()
Where ever I needed to update and done. I know, not very efficient, but I'm very short on time and it will have to do.
Upvotes: 2