文件上传和javascript或自定义验证器 [英] Fileupload and javascript or custom validator
本文介绍了文件上传和javascript或自定义验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有一个asp:fileupload用于上传文件.
但是我需要一些JavaScript或可以使用自定义验证器来显示fileupload的内容长度不能超过限制.
Hello,
i have a asp:fileupload for uploading files.
But i need some javascript or can use custom validator to show the content length of fileupload can not exceed a limit.
推荐答案
使用自定义验证器控件.
http://www.codedigest.com/CodeDigest/65文件大小验证在File-Upload-控件中的ASP-Net.aspx
使用Javascript
http://forums.asp.net/t/1373336.aspx
Using Custom Validator Control.
http://www.codedigest.com/CodeDigest/65-File-Size-Validation-in-FileUpload-control-in-ASP-Net.aspx
Using Javascript
http://forums.asp.net/t/1373336.aspx
<asp:fileupload id="FileUpload1" runat="server" xmlns:asp="#unknown" />
将div放在
Put a div behind
保留错误消息
to hold the error message
<div id="spnErrorLogo" runat="server">
</div>
现在在代码后面添加以下代码
Now add the following code at code behind
Int64 intFileSize = Convert.ToInt64(FileUpload1.PostedFile.ContentLength);
if (intFileSize > 3145728)
{
spnErrorLogo.InnerHtml = "Maximum file size exceeded.
Please upload a file less than 3 MB in size.";
}
如果要上传较大类型的文件
在Web.config中
If you are uploading larger type file
in Web.config
<system.web>
<httpruntime>
executionTimeout="90"
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
enableVersionHeader="true"
/>
</system.web></httpruntime>
将值更改为您选择的其他值(8 Mb为8192,16 Mb为16384,64 Mb为65536.
可能会帮助
change the value to some other value of your choice (8192 for 8 Mb, 16384 for 16 Mb, 65536 for 64 Mb.
may help
这篇关于文件上传和javascript或自定义验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文