So, a bit complicated and I'm guessing there's an issue with my JavaScript so any help would be appreciated.
Here's my code:
Master Page
ASPX
ASCX
ASCX.VB
CSS
My problem is that when I drag a file to the DropZone for either of the controls, both 'fileUploaded' functions are called and the file is uploaded twice. If I drag to the actual AsyncControl itself, everything works fine and the file is only uploaded once.
Help!?
Tony.
Here's my code:
Master Page
function pageLoad() { if (!Telerik.Web.UI.RadAsyncUpload.Modules.FileApi.isAvailable()) { $(".dropzone h5").hide(); $(".dropzone p").hide(); $(".dropzone").removeClass("dropzone"); } else { $(document).bind({ "drop": function (e) { e.preventDefault(); } }); $(".dropzone").each(function (index) { $(this).bind({ "dragenter": function (e) { dragEnterHandler(e, $(this)); } }) .bind({ "dragleave": function (e) { dragLeaveHandler(e, $(this)); } }) .bind({ "drop": function (e) { dropHandler(e, $(this)); } }); }); }}ASPX
<%@ Register Src="~/admin/widgets/assetmanager.ascx" TagPrefix="uc" TagName="AssetManager" %><uc:AssetManager runat="server" ID="Slides" /><uc:AssetManager runat="server" ID="Boxes" />ASCX
<telerik:RadScriptBlock runat="server" ID="RadScriptBlock1"> <script type="text/javascript"> //.Master file needs: function pageLoad() { loadAsync() } //Utils.js - loadAsync(), dropHandler(), dragEnterHandler(), dragLeaveHandler() function fileUploaded<%= AsyncUpload1.ClientID %>(sender, args) { alert("fileUploaded<%= AsyncUpload1.ClientID %>"); $(".invalid.msg" + <%= AsyncUpload1.ClientID %>).hide(); $find("<%=RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("RebindAssets<%= AsyncUpload1.ClientID %>"); $telerik.$(".invalid.msg" + <%= AsyncUpload1.ClientID %>).html(""); sender.deleteFileInputAt(0); } function validationFailed<%= AsyncUpload1.ClientID %>(sender, args) { alert("validationFailed<%= AsyncUpload1.ClientID %>"); $(".invalid.msg" + <%= AsyncUpload1.ClientID %>).show(); $(".invalid.msg" + <%= AsyncUpload1.ClientID %>).html("Sorry, you are trying to upload an invalid type of file."); if ($(".filetypes").text() != "") { var types = $(".filetypes").text().replace("(", "").replace(")", ""); $(".invalid.msg" + <%= AsyncUpload1.ClientID %>).append(" You can upload the following types of file: " + types + "."); } sender.deleteFileInputAt(0); } </script> <script type="text/javascript"> //Telerik.Web.UI.RadAsyncUpload.Modules.Flash.isAvailable = function () { return false; }; Telerik.Web.UI.RadAsyncUpload.Modules.Silverlight.isAvailable = function () { return false; }; </script></telerik:RadScriptBlock><telerik:RadCodeBlock runat="server" ID="RadCodeBlock1"> <span class="msg error invalid msg<%= AsyncUpload1.ClientID %>" style="display:none;"></span></telerik:RadCodeBlock><div id="pnlDropZone" runat="server" class="dropzone dr{0}"> <h5>To upload, drop files here</h5> <p>or</p> <telerik:RadAsyncUpload runat="server" ID="AsyncUpload1" MultipleFileSelection="Automatic" MaxFileSize="52428800" Localization-Select="Select Files" DropZones=".dropzone" /> </div>ASCX.VB
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load Dim manager As RadAjaxManager = RadAjaxManager.GetCurrent(Page) AddHandler manager.AjaxRequest, AddressOf assets_AjaxRequest manager.AjaxSettings.AddAjaxSetting(manager, AsyncUpload1) manager.AjaxSettings.AddAjaxSetting(manager, ddlMoveTo) If Not IsPostBack Then AsyncUpload1.TargetFolder = "~/Images" AsyncUpload1.OnClientFileUploaded = "fileUploaded" & AsyncUpload1.ClientID AsyncUpload1.OnClientValidationFailed = "validationFailed" & AsyncUpload1.ClientID pnlDropZone.Attributes("class") = pnlDropZone.Attributes("class").Replace("{0}", AsyncUpload1.ClientID) End IfEnd SubProtected Sub AsyncUpload1_FileUploaded(sender As Object, e As Telerik.Web.UI.FileUploadedEventArgs) Handles AsyncUpload1.FileUploaded e.File.SaveAs(HttpContext.Current.Server.MapPath("~/images/" & e.File.FileName)) 'Add to databaseEnd SubCSS
.dropzone{ text-align:center; padding:15px; border:dashed 5px #c0c0c0;}.dropzone h5{ margin:0;}.dropzone .RadUpload{ margin:5px auto 0; text-align:center;}.dropzone .RadUpload li{ list-style:none;}.dropzone .RadUpload input.ruFakeInput{ display: none;}My problem is that when I drag a file to the DropZone for either of the controls, both 'fileUploaded' functions are called and the file is uploaded twice. If I drag to the actual AsyncControl itself, everything works fine and the file is only uploaded once.
Help!?
Tony.
