简体   繁体   English

无法在我的asp.net应用程序中使用jQuery单击拖放区

[英]Unable to make the drop-zone clickable with jQuery in my asp.net application

I am working on an asp.net web form application where I have to use a drop-zone so that users can upload files on it. 我正在开发一个asp.net Web表单应用程序,在该应用程序中必须使用放置区,以便用户可以在其上上传文件。

On my existing code, the drop-zone is working fine. 在我现有的代码上,放置区工作正常。 Files are uploading appropriately when I release them on the drop-zone, However, I want to make it clickable so that when a user will click anywhere in that zone, the file upload dialog must open so that a file can be selected for upload. 当我在放置区域上释放文件时,文件正在适当地上传,但是,我想使其可单击,以便当用户单击该区域中的任何位置时,必须打开文件上传对话框,以便可以选择文件进行上传。

I have searched for different techniques on google but unable to find the right code which can work in my case. 我在Google上搜索了不同的技术,但是找不到适合我的情况的正确代码。 Is there any way that can help me achieve my goal easily? 有什么方法可以帮助我轻松实现目标?

My drop-zone HTML is here. 我的拖放区HTML在这里。

<div id="dZUpload" class="dropzone">
  <div class="dz-default dz-message"></div>
</div>

I am looking to achieve this goal with the following jQuery code in document.ready. 我希望通过document.ready中的以下jQuery代码实现此目标。

          var userEmail = $("#hdnFolderPath").val();
          var uploadButton = document.querySelector("#upload");

          Dropzone.autoDiscover = false;

          $("#dZUpload").dropzone({
              url: "/ReceiptStorage/Handlers/FileHandler.ashx",
              params: {
                  DestinationPath: userEmail
              },
              autoProcessQueue: false,
              addRemoveLinks: true,

              init: function () {
                  var uploadButton = document.querySelector("#upload");
                  var dZUpload = this; //closure

                  dZUpload.on("complete", function (file, response) {
                      if (file.status === 'success') {
                          dZUpload.removeFile(file);
                          LoadFiles($("#hdnFolderPath").val());
                      }
                  });
                  dZUpload.on('error', function (file, response) { 
                  });
                  uploadButton.addEventListener("click", function () {
                      if (dZUpload.files.length > 0)
                          dZUpload.processQueue();
                  });
              }    
          });

I was missing clickable feature within my code. 我的代码中缺少可点击的功能。 By including clickable: true, above 通过包含clickable:true,在上方

init: function () { 初始化:函数(){

I am able to see the file upload dialog open after clicking anywhere in the drop-zone. 单击放置区域中的任意位置后,我可以看到打开了文件上传对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM