How do I change the default text on a file upload control?

Michael Sterling
Michael Sterling used Ask the Experts™
on
I'm uploading a file, using an asp FileUpload control but want to change the default text after a successful upload. When the control/page renders the default text is: "No file selected". It also defaults to this after the successful upload. I'd like to change it to something else if that's possible? Thanks.

<asp:FileUpload ID="flupldIAAPhotos" runat="server" />

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Shaun VermaakSenior Consultant
Awarded 2017
Distinguished Expert 2018

Commented:
If all fails, you should be able to style/change the resulting code with JQuery
Michael SterlingWeb Applications Developer

Author

Commented:
ok. do you have an example?
Senior Full Stack Developer
Distinguished Expert 2017
Commented:
Have a look at this thread: Asp:FileUpload edit “No file selected” message.

You replace the text with your own message using CSS pseduo-class :after. You can declare a class like this one:
.bar:after {
    content:"Please select a file";
    background-color:white;
}

Open in new window


And assign it to your FileUpload control. The content message will replace the original one. Of course upon file selection you need to remove the message, you can do this for example via jQuery  .removeClass (assuming ID of your FileUpload is "foo"):
$('#foo').change(function() {
    $(this).removeClass("bar");
})

Open in new window


Here is the example code in JSFiddle. Check it out for a working example.

Note that this solution seems to work Webkit-browser's only (Chrome, Opera, Safari) you may need an alternative for others
Michael SterlingWeb Applications Developer

Author

Commented:
Sorry about the delay, but you're correct about the browsers. Don't know how to make it work for IE though which, of course, is the browser that 99% of my users, use haha. Go figure, but thanks for the help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial