Asp:FileUpload edit "No file selected" message
Asked Answered
G

7

5

I just need to know if there's a way to change the message shown by the Asp:FileUpload when no file as been selected.

This message

Thanks.

Ganof answered 25/11, 2013 at 19:21 Comment(1)
possible duplicate of #17470344Interlanguage
D
4

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;
}

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");
})

Demo: http://jsfiddle.net/5zhuL/2/

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

Disconsolate answered 25/11, 2013 at 19:38 Comment(0)
I
5

http://jsfiddle.net/ZDgRG/

See above link. I use css to hide the default text and use a label to show what I want:

html

<div>
      <input type='file' title="Choose a video please" id="aa" onchange="pressed()">
      <label id="fileLabel">Choose file</label>
</div>

css

input[type=file]{
    width:90px;
    color:transparent;
}

javascript

window.pressed = function(){
    var a = document.getElementById('aa');
    if(a.value == "")
    {
        fileLabel.innerHTML = "Choose file";
    }
    else
    {
        var theSplit = a.value.split('\\');
        fileLabel.innerHTML = theSplit[theSplit.length-1];
    }
 };
Interlanguage answered 25/11, 2013 at 19:31 Comment(0)
D
4

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;
}

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");
})

Demo: http://jsfiddle.net/5zhuL/2/

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

Disconsolate answered 25/11, 2013 at 19:38 Comment(0)
S
1

Nope, not possible. This is the standard rendering in Chrome and cannot be changed.

Sacttler answered 25/11, 2013 at 19:25 Comment(0)
F
1

If you visit your page source in your browser ASP.NET put an input element with type='file' instead of your FileUpload. You could simply use CSS to cover the text with something when the value attribute is empty.

Freemon answered 25/11, 2013 at 19:25 Comment(0)
M
0

Only add this CSS to your code. It simply hide the "No file chosen".

<style>
 input[type=file]
{
width:90px;
color:transparent;
}

</style>
Monostome answered 14/4, 2015 at 10:55 Comment(0)
P
0

http://jsfiddle.net/Lsgbx5ne/1/

input[type=file]{
  color:transparent;
}
input[type=file]:after {
  color: #000;
  content:" Cool!";
}

Improvements over other solutions:

  • Works for short text
  • Doesn't change the background color
  • Pure css
Pyrene answered 28/5, 2015 at 17:29 Comment(0)
D
0

This work in all browser

window.pressed = function(){
    var a = document.getElementById('aa');
    if(!(a.value == ""))
    {
        var theSplit = a.value.split('\\');
        fileLabel.innerHTML = theSplit[theSplit.length-1];
    }
};
input[type=file]{
    width:90px;
    color:transparent;
}
<div>
<input type='file' title="Choose a video please" id="aa" onchange="pressed()">
<label id="fileLabel">Choose file</label>
</div>
Declared answered 30/3, 2016 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.