我想打印一条错误消息,但我无法提供帮助
这是我从网上某处找到的 javascrpit
<script type="text/javascript">
function AjaxUpload1_OnUploadComplete(sender, e) {
var size = e.get_fileSize();
if (size > 289496) {
var err = new Error();
err.name = 'My API Input Error';
err.message = 'Filesize Error';
throw (err);
}
else {
var div = document.getElementById("status");
div.innerHTML += "<p>uploaded: " + e.get_fileName() + "</p>";
}
}
</script>
阿贾克斯
<ajaxToolkit:AjaxFileUpload
id="AjaxUpload1"
OnUploadComplete="AjaxUpload1_OnUploadComplete"
MaximumNumberOfFiles="5"
AllowedFileTypes="jpg,jpeg,gif,png"
ThrobberID="MyThrobber"
runat="server" />
<asp:Image
id="MyThrobber"
ImageUrl="/images/indicator.gif"
Style="display:none"
runat="server" />
代码隐藏
protected void AjaxUpload1_OnUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string filePath = "~/images/ajax/" + e.FileName;
AjaxUpload1.SaveAs(Server.MapPath(filePath));
}
网络配置
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
</handlers>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="289496"/>
</requestFiltering>
</security>
</system.webServer>
上传工作和文件大小是好的,但是当用户选择一个大于限制的文件时我想打印一个错误。