Fairy_G
Fairy_G

Reputation: 417

asp.net fileupload Vanishes on postback without AJAX

I m using asp.net 2.0 without AJAX. The file path in the fileupload control gets vanished once the postback take places. i do some validations for other controls in code behind. i need to upload the file again for further processing. can any one suggest me how to hold the filepath in the fileupload control even after postback.

Upvotes: 2

Views: 1596

Answers (2)

Vijay
Vijay

Reputation: 2133

I agree with Silky. FileInput control cannot hold value across post backs.

A possible workaround for this can be how GMail handles uploading attachments. The file can be placed in some temporary location on server and after the post back, display a label indicating that the file is already selected and provide a remove button. A problem here is that you have to consider cleaning up such files.

Upvotes: 2

Noon Silk
Noon Silk

Reputation: 55182

It's not possible, for security reasons. You cannot set the field on the client side, and it will not stay set, after you post. The security reason is that, if it were allowed to be set, you could arbitrarily upload any file from the users computer, which would be bad.

Upvotes: 1

Related Questions