admin管理员组文章数量:1322838
I am using a <asp:FileUpload>
to upload a PDF file to my web page. But after clicking on browse the window opens, and once I select a file and click on Open
i want to get the file name and display it in a Label
. What function should I use in ASP.NET
to do this? I tried the OnLoad
, OnUnload
, OnDataBinding
, etc. in the <asp:FileUpload>
but nothing works. Can someone suggest me a solution for this?
My code is as below:
<asp:FileUpload ID="fileUpload" runat="server" /><br />
<asp:Label ID="labelFilename" runat="server" Text=""></asp:Label>
Once I select a file and click open the file name should be displayed in the label.
I am using a <asp:FileUpload>
to upload a PDF file to my web page. But after clicking on browse the window opens, and once I select a file and click on Open
i want to get the file name and display it in a Label
. What function should I use in ASP.NET
to do this? I tried the OnLoad
, OnUnload
, OnDataBinding
, etc. in the <asp:FileUpload>
but nothing works. Can someone suggest me a solution for this?
My code is as below:
<asp:FileUpload ID="fileUpload" runat="server" /><br />
<asp:Label ID="labelFilename" runat="server" Text=""></asp:Label>
Once I select a file and click open the file name should be displayed in the label.
Share Improve this question asked Sep 16, 2017 at 7:20 Mano Prathibhan CMano Prathibhan C 5182 gold badges13 silver badges38 bronze badges 02 Answers
Reset to default 7You can use this code:
<script>
$(document).ready(function () {
$('#fileUpload').change(function () {
var path = $(this).val();
if (path != '' && path != null) {
var q = path.substring(path.lastIndexOf('\\') + 1);
$('#labelFilename').html(q);
}
});
});
</script>
You can access the file name(server side) by using following code snippet
string file_name=fileUpload.FileName.ToString();
You can access the filename on client side using following code snippet
$(document).ready(function () {
$("#fileUpload").change(function () {
var FileUpload = $("#fileUpload").val();
... }
}
版权声明:本文标题:javascript - How to get file name from asp:FileUpload and display in a Label using ASP.NET and C# - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742116308a2421481.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论