Anyway to dynamically set text in an asp:FileUpload?
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?
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.
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.
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 >.
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.
精彩评论