Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp:FileUpload edit "No file selected" message

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.

like image 619
Guillermo Oramas R. Avatar asked Nov 25 '13 19:11

Guillermo Oramas R.


People also ask

How do I get rid of no file selected in HTML?

and add an html inline-title attribute to the element to hide the "No File Chosen" hover text. or, you could do it all with JavaScript.

How do I restrict a file type in FileUpload control?

By default the FileUpload control doesn't have a property to restrict file types when the select file window is opened. However, you can check the file uploaded extension before continuing the process. Its simple. Get the extension of the file selected via FileUpload control using the below code.

How do I stop FileUpload control from clearing on postback?

The simple solution for preventing file loss from an upload control on postback is to put the upload control outside of an update panel control on a . aspx page. Or, in other words, put all the input controls that might trigger a postback inside an update panel.

What is FileUpload control in asp net?

ASP.NET FileUpload control allows us to upload files to a Web Server or storage in a Web Form. The control is a part of ASP.NET controls and can be placed to a Web Form by simply dragging and dropping from Toolbox to a WebForm. The FileUpload control was introduced in ASP.NET 2.0.


2 Answers

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];
    }
 };
like image 153
Chandan Kumar Avatar answered Oct 20 '22 07:10

Chandan Kumar


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.

like image 40
Yuriy Galanter Avatar answered Oct 20 '22 07:10

Yuriy Galanter