How can I cancel ajaxToolkit: AjaxFileUpload inside OnClientUploadStart?

I am trying to do some validation of some other fields on a page after the user clicks the download button of the ajaxfileupload control. OnClientUploadStart is defined to run before loading starts. and it works. but I want to cancel the download if the verification fails. I tried to do "return false"; but it didn’t work. How can I cancel the download?

if check failed, I want to cancel

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
source share
2 answers

To start the download manually, you can use this script:

 function startUpload(){ $get("<%= AjaxFileUpload1.ClientID %>_UploadOrCancelButton").click(); } 
+1
source

Cancel the download of large files (works only for browsers that support 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" /> 
+1
source

Source: https://habr.com/ru/post/1496872/


All Articles