Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML File Object

Status
Not open for further replies.

JohnnyBGoode

Programmer
May 1, 2002
76
CA
I would like to use a "Browse" type of object so that the user may choose a file by drilling through their file folders. I could not find a Web Form object for this use. I had to use the HTML object "File Field". The problem with this is as follows. When you submit the page, if there is an error, the user will be brought back to the page to correct these errors. All other Web Form objects keep their entered values. The HTML File Field object does not. It blanks it out every time. There is no way (as far as I have found) to populate this File Field with any sort of value. Is there any other way around this? I would either like to populate the File Field with something, or use an object that will keep its value.
 
Hi Johnny,

If you include runat=&quot;server&quot; in your <input type=&quot;file&quot; ... /> tag, you can use it like any other servercontrol, and it will save viewstate as well I think.

regards,
Blaxo
 
What you want is the path the user entered in the file input. f.e &quot;C:\Documents\myfile.jpg&quot;, so that you can repopulate the textbox with this value after a postback, right?

I have a feeling that, since the input is of type &quot;file&quot;, the actual text content of that control is not being submitted with the request, but the bytes that are the posted file.

If this is true, it may be that the only way to capture the path text would be to write a javascript that fires when youre page is submitted that will grab the contents of that text box and submit it in a hidden field to the server. Then, on the server, grab that hidden field from the request params and persist it to viewstate manually.

Even then, though, I can't be sure that viewstate would repopulate an input of type file.

Tough one.

Regards,






David
[pipe]
 
Is there another way to bring up the file folders and select a file? Is there an object that I can call upon clicking a standard button? Then, this could be populated into a standard textbox.
 
Actually.. I don't think it's possible to assign anything to the text field of the file input element. That's probably why asp.net can't save it's viewstate.

If you could do that it would be very simple to get any file from the users harddrive ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top