Output file name to label from Fileupload control - ASP.NET 4.0 C #

Is it possible to fire an event after I have selected a file in the Fileupload control, so I can set Label1.Text = FileUpload.FileName;

Or, if any of you had another idea, which would also be awesome (maybe some kind of javascript)! :)

+3
source share
1 answer

You can listen to the event changeon the client side. Here is the syntax for IE, but you can adapt it for 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 am sure that good browsers will only report the file name, where IE also reports the full path (wrong).

+4
source

Source: https://habr.com/ru/post/1770534/


All Articles