javascript在Asp.net验证上传文件的文件类型的

 
  
<% @ Page Language = " C# " MasterPageFile = " ~/VQPMaster.master " AutoEventWireup = " true " CodeFile = " importQuotation.aspx.cs " Inherits = " ImportExcel_importQuotation " Title = " Untitled Page " %>

< asp:Content ID ="Content1" ContentPlaceHolderID ="ContentPlaceHolderMain" Runat ="Server" >
< script type ="text/javascript" src ="../js/jquery-1.5.2.js" ></ script >
< script language ="javascript" type ="text/javascript" >

$(document).ready(
function (){
var fileUpload = $( " #<%=fileUpload.ClientID%> " );
var txtEmail = $( " #<%=txtEmail.ClientID%> " );
var lblMessage = $( " #<%=lblMessage.ClientID%> " );
lblMessage.text();
$(
" #<%=btnSubmit.ClientID%> " ).click( function (){
if (fileUpload.val() == "" ){
fileUpload.focus();
lblMessage.text(
" please upload file! " );
return false ;
}
else // valid the upload file extension file name!
{
var hash = {
' .XLS ' : 1 ,
' .XLSX ' : 1
};
var re = / \..+$ / ;
var ext = fileUpload.val().toUpperCase().match(re);
if ( ! hash[ext]) {
lblMessage.text(
" Invalid filename, please select another file! " );
return false ;
}
}
if (txtEmail.val() == "" ){
lblMessage.focus();
lblMessage.text(
" please input user email! " );
return false ;
}


})
$(
" #btnReset " ).click( function (){
lblMessage.text(
"" )
})
})
</ script >

< div id = "divUploadMain" style =" margin : 5px 0px 0px 4%; " >
< div id = "divFileUpload" style ="height : 30px; margin-bottom : 5px;" >
Quote
&nbsp;&nbsp;&nbsp;&nbsp; File &nbsp; : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; < asp:FileUpload ID ="fileUpload" runat ="server" Width ="464px" />
</ div >
< div id = "divEmail" style ="height : 30px; margin-top : 5px;" >
MAPS
&nbsp; Email &nbsp; contact &nbsp; :
< asp:TextBox ID ="txtEmail" runat ="server" Width ="464px" ></ asp:TextBox >
</ div >
< div id ="divBtns" >
< asp:Button ID ="btnSubmit" runat ="server" Text ="Submit" /> &nbsp;
< input id ="btnReset" type ="reset" value ="Reset" /> &nbsp;
< asp:Label ID ="lblMessage" runat ="server" ForeColor ="Red" Visible ="true" Text ="" ></ asp:Label ></ div >
</ div >
</ asp:Content >

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值