4

在用户单击 ajaxfileupload 控件的上传按钮后,我正在尝试对页面上的其他一些字段进行一些验证。OnClientUploadStart 被定义为在上传开始之前触发。它有效。但如果验证失败,我想取消上传。我试着做“return false;” 但这没有用。如何取消上传?

如果验证失败,那么我想取消

 function uploadStart(sender, args) {

            var FileDescription = document.getElementById("FileDescription").value;

            alert( FileDescription);
         return false;
         }  
<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1"
    ThrobberID="myThrobber" OnUploadComplete="AjaxFileUpload1_UploadComplete"
    ContextKeys="" OnClientUploadError="uploadError" OnClientUploadComplete="uploadComplete" OnClientUploadStart="uploadStart" 
    AllowedFileTypes="jpg,jpeg,doc,xls"
    MaximumNumberOfFiles="1"
    runat="server"/>  
4

2 回答 2

1

要开始手动上传,您可以使用此脚本:

function startUpload(){
    $get("<%= AjaxFileUpload1.ClientID %>_UploadOrCancelButton").click();
}
于 2013-08-14T19:49:24.527 回答
1

取消下载大文件(仅适用于支持 HTML5 的浏览器)。

    function uploadStartedAjax(sender, args) {
        var maxFileSize = $('#MaxRequestLength').val();
        for (var i = 0; i < sender._filesInQueue.length; i++) {
            var file_size = sender._filesInQueue[i]._fileSize;
            if (file_size > maxFileSize) {
                sender._filesInQueue[i].setStatus("cancelled", Sys.Extended.UI.Resources.AjaxFileUpload_Canceled+' - too large(> ' + maxFileSize + ' byte)!');
                sender._filesInQueue[i]._isUploaded = true;
            } //End if
        } //End for
        return true;
    }
    <ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" runat="server" MaximumNumberOfFiles="200"  Width ="750px" 
                                OnClientUploadStart="uploadStartedAjax" />
于 2015-02-17T13:34:31.757 回答