Put in a TextBox the name of an asp file: FileUpload

1

I have a file upload in ASP.net to which I want to change the look and feel to be seen as bootstrap but since there is no direct conversion I have to use a button and a textbox to emulate its behavior, I have these elements

<asp:FileUpload ID="FileUpload1" runat="server"/>
<asp:Button ID="Button1" runat="server" Text="Button" CssClass="btn btn-default" />
<asp:TextBox ID="TextBox1" runat="server" CssClass="form-control"></asp:TextBox>

and I have this code to place in the TextBox1 the name of the file selected with FileUpload, but it is not working:

$(document).ready(function () {
  $(document).on('change', '#<% FileUpload1.ClientID %>', function (e) {
                    $('#<% TextBox1.ClientID %>').val(e.target.files[0].name);)};
});

Does anyone know why this code does not work?

    
asked by YHAM 13.02.2017 в 21:43
source

1 answer

0

I found the problem, the code was badly written, it should be like that

$(document).ready(function () {
  $(document).on('change', '#<%= FileUpload1.ClientID %>', function (e) {
                    $('#<%= TextBox1.ClientID %>').val(e.target.files[0].name);});
});
    
answered by 14.02.2017 / 15:22
source