I'm using JavaScript to toggle the visibility of a div that contains a FileUpload Control. If someone clicks "browse" on the control, selects a file, then toggle's the visibility to 'Hidden', the FileUpload control still has that path listed, eventhough
it's not visible. When they click the submit button, the file is still uploaded to the server, eventhough you can no longer see the control.
Does anyone know how I can accees the textbox within the FileUpload control, so I can remove the path?
//This works for a TextBox Control
var textBox = document.getElementById("<%=TextBox1.ClientID %>").innterText =
"";
//Can I do the same for the TextBox in a FileUpload control?
var fileUpload = document.getElementById("<%=fileUpload1.ClientID %>").innterText =
"";
"Don't sweat the petty things, and don't pet the sweaty things"
- George Carlin
Nope. That won't work, I promise, because it's impossible to change that. The FileUpload control's value is
ReadOnly, so you will never be able to alter its value. And there is good reasoning for this. If it was not read only, then you can have some javascript change the value of it to a different file path than the user selected, and then it would
upload that file to the server without the user's permission. That would be tragic. Make sense?
Hope this helps! Please mark the helpful post(s) as Answer.
Instead of trying to manipulate the textbox within the fileupload control, I just disabled it. So, if someone enters a file path into the control, then changes their mind and toggles the visibility to hidden, the control is disabled and that file isn't
uploaded.
Thanks again.
"Don't sweat the petty things, and don't pet the sweaty things"
- George Carlin
Marked as answer by barryman9000 on Oct 10, 2007 05:51 PM
You're welcome! I actually intended on suggesting you disable the control to prevent the file from being uploaded, but it slipped my mind while I was thinking how to explain the security precaution.
barryman9000
Participant
1698 Points
605 Posts
The textbox in a FileUpload control
Oct 10, 2007 04:34 PM|LINK
I'm using JavaScript to toggle the visibility of a div that contains a FileUpload Control. If someone clicks "browse" on the control, selects a file, then toggle's the visibility to 'Hidden', the FileUpload control still has that path listed, eventhough it's not visible. When they click the submit button, the file is still uploaded to the server, eventhough you can no longer see the control.
Does anyone know how I can accees the textbox within the FileUpload control, so I can remove the path?
//This works for a TextBox Control
var textBox = document.getElementById("<%=TextBox1.ClientID %>").innterText = "";
//Can I do the same for the TextBox in a FileUpload control?
var fileUpload = document.getElementById("<%=fileUpload1.ClientID %>").innterText = "";
- George Carlin
JustinHolton
Member
516 Points
114 Posts
Re: The textbox in a FileUpload control
Oct 10, 2007 04:58 PM|LINK
This should work..
document.getElementById("<%=fileUpload1.ClientID %>").value = '';barryman9000
Participant
1698 Points
605 Posts
Re: The textbox in a FileUpload control
Oct 10, 2007 05:07 PM|LINK
Thanks for the reply. That did't seem to work though. Using .value does work for the asp:TextBox though. Rather than using innerText I mean.
Any other ideas?
- George Carlin
JoshStodola
Star
13736 Points
3177 Posts
Re: The textbox in a FileUpload control
Oct 10, 2007 05:09 PM|LINK
Nope. That won't work, I promise, because it's impossible to change that. The FileUpload control's value is ReadOnly, so you will never be able to alter its value. And there is good reasoning for this. If it was not read only, then you can have some javascript change the value of it to a different file path than the user selected, and then it would upload that file to the server without the user's permission. That would be tragic. Make sense?
Hope this helps! Please mark the helpful post(s) as Answer.
barryman9000
Participant
1698 Points
605 Posts
Re: The textbox in a FileUpload control
Oct 10, 2007 05:51 PM|LINK
Yeah, makes sense. Thanks for the help.
Instead of trying to manipulate the textbox within the fileupload control, I just disabled it. So, if someone enters a file path into the control, then changes their mind and toggles the visibility to hidden, the control is disabled and that file isn't uploaded.
Thanks again.
- George Carlin
JoshStodola
Star
13736 Points
3177 Posts
Re: The textbox in a FileUpload control
Oct 10, 2007 06:40 PM|LINK
You're welcome! I actually intended on suggesting you disable the control to prevent the file from being uploaded, but it slipped my mind while I was thinking how to explain the security precaution.
Best regards...