# Show Confirm Dialog before Uploading Files

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Upload</td>
 </tr>
 <tr>
  <td>Operating System</td>
  <td>All</td>
 </tr>
 <tr>
  <td>Browser</td>
  <td>All</td>
 </tr>
 <tr>
  <td>Browser Version</td>
  <td>All</td>
 </tr>
</table>

## Description

How can I implement a confirm dialog before the user uploads a file when the Upload is in asynchronous mode?

## Solution

Use the [Kendo UI Confirm Dialog](https://demos.telerik.com/kendo-ui/dialog/predefined-dialogs) and an [Asynchronous Upload Mode](https://docs.telerik.com/aspnet-mvc/html-helpers/editors/upload/modes-of-operation#asynchronous-mode) with [AutoUpload](https://docs.telerik.com/kendo-ui/api/ui/upload/configuration/async.autoupload) **turned off**.<br>

> This is a customized solution that does not support other modes. Such as [Chunk Upload](https://docs.telerik.com/aspnet-mvc/html-helpers/editors/upload/chunk-upload) or [Synchronous Mode](https://docs.telerik.com/aspnet-mvc/html-helpers/editors/upload/modes-of-operation) of operation.

To achieve the desired outcome:

1. Subscribe to the [Select](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/uploadeventbuilder#selectsystemstring) event handler of the Upload.
2. Within the handler, remove the default click handler from the upload button programmatically by using the [off](https://api.jquery.com/off/) jQuery method.
3. Prevent the default upload workflow.
4. Depending on the user's response from the dialog, either call the [upload](https://docs.telerik.com/kendo-ui/api/ui/upload/methods/upload?_gl=1*102tlvl*_gcl_au*MTU0Nzc4NDk1LjE3MjAxODc4MjM.*_ga*Mzc1Nzg4OTUxLjE3MjAxODc4MjE.*_ga_9JSNBCSF54*MTcyNDEzODY3OS4xNi4xLjE3MjQxNjUyNzguNTQuMC4w#upload) method if confirmed or the [removeAllFiles](https://docs.telerik.com/kendo-ui/api/ui/upload/methods/removeallfiles?_gl=1*102tlvl*_gcl_au*MTU0Nzc4NDk1LjE3MjAxODc4MjM.*_ga*Mzc1Nzg4OTUxLjE3MjAxODc4MjE.*_ga_9JSNBCSF54*MTcyNDEzODY3OS4xNi4xLjE3MjQxNjUyNzguNTQuMC4w#removeallfiles) method if cancelled.

The following example demonstrates how to implement these steps:

```Razor HtmlHelper
   @(Html.Kendo().Upload()
    .Name("files")
    .Async(a => a   
        .Save("OnPostUpload", "Home")   
        .Remove("OnPostRemove", "Home") 
        .AutoUpload(false)
    )
    .Events(ev => ev.Select("onSelect"))
)
```

```JS script.js
<script>
    function onUpload(e){
        let upload = $("#files").getKendoUpload();

        kendo.confirm("Confirm Uploading")
            .done(function () {
                /* The result can be observed in the DevTools(F12) console of the browser. */
                console.log("User accepted");
                upload.upload();
            })
            .fail(function() {
                /* The result can be observed in the DevTools(F12) console of the browser. */
                console.log("User rejected");
                upload.removeAllFiles();                
            });
    }
    function onSelect(e) {
        setTimeout(function () {
            var uploadBtn = e.sender.wrapper.find(".k-upload-selected");
            $(e.sender.wrapper).off("click",".k-upload-selected");
            $(uploadBtn).bind("click", onUpload);
        }, 200)
    }
</script>
```

For a runnable example based on the code above, refer to the [REPL example on Confirmation Before Uploading Files](https://netcorerepl.telerik.com/Qyksbplf39vN1b5R08).

## More ASP.NET MVC Upload Resources

* [ASP.NET MVC Upload Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/upload/overview)

* [ASP.NET MVC Upload Demos](https://demos.telerik.com/aspnet-mvc/upload)

* [ASP.NET MVC Upload Product Page](https://www.telerik.com/aspnet-mvc/upload)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Upload for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/upload)

* [Server-Side API Reference of the Upload for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/upload)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2024-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
