Reputation: 4869
When the user selects an item from a dropdownlist containing image names, I would like the FileUpload text box to be filled with a message I program such as "Replace this image with..." How would I do this?
Upvotes: 1
Views: 3341
Reputation: 101
Like others have said, there is no way to directly change the text of the file name box, but what you can do is create a label and use positioning to make sure the label appears directly above the uploader.
<span runat="server" id="SelectedFileSpan" style="position: absolute; top: 10px; left: 12px">
<asp:Label runat="server" ID="FileNameLabel"></asp:Label>
</span>
<asp:FileUpload runat="server" ID="FileUploader" />
Then set the text of the label.
Upvotes: 0
Reputation: 11211
Not possible. The < input type="file" /> is part of the browser chrome. Some browsers don't show any text at all, so any solution would not be robust. As Bryan suggests, use a < label >.
Upvotes: 0
Reputation: 3637
Due to the nature of the control, for security reasons you cannot manipulate it beyond some styling.
What you can do, however, is use a Flash or Silverlight based upload control. Or put your desired message in a label above the file input.
Upvotes: 1
Reputation: 17652
Security restrictions in certain browsers (IE at least) prevent you from being able to actually set the text of an <input type="file" />
element, which is what the FileUpload ASP.NET control renders.
I am on a project where we are trying to manipulate the appearance of file upload elements, and it's proving to be quite difficult to do in a cross-browser-compliant manner. I suggest looking at flash-based solutions such as Uploadify, which is more customizable.
Upvotes: 2