hello...i have a fileupload control on my page and if i browse to a file(i.e.,now the fileupload control's property 'hasfile' is 'true') and then if i post back the page for any validations, the fileupload control is getting cleared,i.e., now the user again has to browse to the same specific file.Please suggest me any help so that the selected(browse ) file do not vanish.I will be very thankful if any solution for this.
fileupload control is getting cleared
Collapse
X
-
You don't have the FileUpload control within an AJAX.Net UpdatePanel control do you?Originally posted by ravitunkhello...i have a fileupload control on my page and if i browse to a file(i.e.,now the fileupload control's property 'hasfile' is 'true') and then if i post back the page for any validations, the fileupload control is getting cleared,i.e., now the user again has to browse to the same specific file.Please suggest me any help so that the selected(browse ) file do not vanish.I will be very thankful if any solution for this.
-FrinnyComment
-
Iam almost done with the post back validations and it would be a huge process for me now to start off again....so please suggest me any idea without going for the client side validations....Originally posted by kenobewanOne way may be to do your validation client side to avoid a postback.Comment
-
Hi Ravitunk,Originally posted by ravitunkIam almost done with the post back validations and it would be a huge process for me now to start off again....so please suggest me any idea without going for the client side validations....
I just tried to solve the problem you're facing and discovered the underlying problem to why your file is being erased from the FileUpload control on postback.
The FileUpload control makes use of the <input type="file"> HTML tag to deal with the file upload.
You cannot set the "value" (file location/name) for this tag and this is why the "filename" attribute for the FileUpload control is ReadOnly.
The reason why you cannot set the this value is pretty obvious...if you were able to set the initial value of the file location/name for the file you want the user to upload you could possibly lure the user into submitting sensitive data to your sever (such as luring them into submitting password files etc).
Some browsers (older ones) will let you set the value for the <input type="file">... but the new browsers will not in order to protect the users from such luring attack.
So this is why your file name/location is being erased ever time there is a PostBack.
I suggest modifying your upload portion so that it does the validation on the file, and if it fails display an error message stating that the file failed to upload and asking them to supply you with a valid file. Otherwise, upload the file and store it into a temp location for the user's session and display a message stating that their file has been uploaded.
I hope this helps you.
Cheers!
-FrinnyComment
Comment