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.
Thanks.
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.
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.
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.
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.
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];
}
};
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With