Override cancel and remove

4 posts, 0 answers
  1. Michael
    Michael avatar
    9 posts
    Member since:
    Dec 2014

    Posted 09 Sep 2015 Link to this post

    I am using a custom Http Handler as described at http://www.telerik.com/forums/radasyncupload-without-temporary-file to upload files directly to a database without using a temporary folder.  This is working correctly, however, if the user clicks 'cancel' or 'remove' the file is obviously not removed from my database.
    Is there a way to override the cancel and remove operations so I can delete the files from my database?

     I've created a new class that inherits from AsyncUploadResult to add a FileID so this should be easy... if I just knew which fuction to override.  Thanks!

  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 11 Sep 2015 Link to this post

    Hi Michael,

    RadAsyncUpload cannot remove uploaded file automatically. That's why you can create webservice which do that. Use jQuery to attach click event to "Cancel/Remove" buttons and call the service.
     
    Regards,
    Hristo Valyavicharski
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael
    Michael avatar
    9 posts
    Member since:
    Dec 2014

    Posted 11 Sep 2015 in reply to Hristo Valyavicharski Link to this post

    In order to not re-invent the wheel, do you have any example code for attaching a jquery event to attach to these buttons in order to call a webservice?
  5. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 14 Sep 2015 Link to this post

    Sample with web method: 

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
    </head>
    <body>
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                <Scripts>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
                </Scripts>
            </telerik:RadScriptManager>
            <script type="text/javascript">
                function fileRemoving(sender, args) {
                    $.ajax({
                        type: "POST",
                        url: "Default.aspx/Remove",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: OnSuccess,
                        failure: function (response) {
                            alert(response.d);
                        }
                     });
                }
     
                function OnSuccess(response) {
                    alert(response.d);
                }
     
            </script>
            <div>
                <telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" OnClientFileUploadRemoving="fileRemoving"></telerik:RadAsyncUpload>
            </div>
        </form>
    </body>
    </html>

    using System;
    using System.Web;
    using System.Web.Services;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Configuration;
    using System.Web.Security;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Telerik.Web.UI;
    using System.Web.Script.Services;
     
    public partial class Default : System.Web.UI.Page
    {
        [WebMethod]
        [ScriptMethod]
        public static int Remove()
        {
            // SQL query that removes file from the DB
            return 200;
        }
    }

    I hope this helps.

    Regards,
    Hristo Valyavicharski
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top