Post filename in label from Fileupload control - ASP.NET 4.0 C#
Is there anyway to run an event after i selected a file in a Fileupload control, so i can set Label1.Text = FileUpload.FileName;
Or if any of you got a开发者_如何学Gonother idea that would be awesome too(maybe some javascript)! :)
You can listen for the change
event on the client side. Here's the syntax for IE but you can adapt it for the better browsers.
<asp:FileUpload ID="FileUpload1" runat="server" /> <span id="txt" />
<script>
var fu = document.getElementById('<% =FileUpload1.ClientID %>');
fu.attachEvent('onchange', function (e) {
document.getElementById('txt').innerHTML = e.srcElement.value;
});
</script>
I'm pretty sure good browsers will report only the filename, where IE with report the full path too (incorrectly).
精彩评论