• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7453
  • Last Modified:

FileUpload empty after PostBack

Hi experts,

I have problem with the FileUpload. When I choose a file and I want to send it, I press the button. But here I have some conditions (like Captcha etc...). When the PostBack occures I can see the FileUpload values, but if captcha is wrong I dont want to save the file.
But when I look at the FileUpload now, it is empty.

What to do to keep the file path set up into the FileUpload also after PostBack please?
0
enkor
Asked:
enkor
  • 5
  • 2
  • 2
  • +1
2 Solutions
 
mayank_joshiCommented:
0
 
enkorAuthor Commented:
I dont need the async uploading, I just need the upload on releasing submitting button. So there is no way to keep the values anyway?
0
 
mayank_joshiCommented:
There isn't a way to get the FileUpload control to retain it's value (or set it to a default value) after a postback. Because of security implications (scripts setting the value, and then attempting to retrieve files of your computer) the value of the fileupload form field is read only. Therefore you cannot set or reset the value either through Javascript or through Server Side Code. The only way to set the value on the FileUpload control is to have the user make a selection.


so  i think there is no method other than AJAX or IFRAME technique.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
enkorAuthor Commented:
ok, thanx. and can anyone gimme the ajax example please? I am not so strong in it.
Thanx
0
 
enkorAuthor Commented:
thanx eugenbv, this is OK. But i had to add this part of code to my web.config:
<system.web>
 <httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="15360" requestLengthDiskThreshold="15360"/>
</system.web>

Open in new window

0
 
eugenbvCommented:
The default size for upload is 256bytes. So in your case (uploading files) makes sense to increase that limit.
0
 
enkorAuthor Commented:
I had no problem with the limit, but it caused error: "Can Not Access A Closed File"

So I have found this: http://www.c-sharpcorner.com/Forums/Thread/43162/can-not-access-a-closed-file.aspx
0
 
Alpesh PatelAssistant ConsultantCommented:
It will not retain the value in control if page validation is wrong as like password field.
0
 
enkorAuthor Commented:
The solution by eugenbv is OK, but did not work me till i have found the <httpRuntime>, so his solution was not absolutely complex.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now