File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ This article explains the events available in the Telerik Upload for Blazor:
20
20
* [ OnSuccess] ( #onsuccess )
21
21
* [ OnError] ( #onerror )
22
22
* [ OnCancel] ( #oncancel )
23
+ * [ OnClear] ( #onclear )
23
24
24
25
25
26
## OnSelect
@@ -665,6 +666,50 @@ You can cancel the event based on a condition (for example, some information abo
665
666
@[ template] ( /_contentTemplates/common/general-info.md#event-callback-can-be-async )
666
667
667
668
669
+ ## OnClear
670
+
671
+ The ` OnClear ` event fires when the user clicks the Clear button which is available when ` AutoUpload="false" ` . You can prevent the action on a condition.
672
+
673
+ @[ template] ( /_contentTemplates/upload/notes.md#events-files-carry-client-validation-info )
674
+
675
+ > caption Handling the OnClear event and cancelling it on condition
676
+
677
+ @[ template] ( /_contentTemplates/upload/notes.md#see-controller-sample-in-overview )
678
+
679
+ ```` CSHTML
680
+ @inject NavigationManager NavigationManager
681
+
682
+ <TelerikUpload SaveUrl="@SaveUrl"
683
+ RemoveUrl="@RemoveUrl"
684
+ OnClear="@OnClearHandler"
685
+ AutoUpload="false">
686
+ </TelerikUpload>
687
+
688
+ @code {
689
+ async Task OnClearHandler(UploadClearEventArgs e)
690
+ {
691
+ // cancel the action if there is exactly 1 file selected
692
+ if(e.Files.Count == 1)
693
+ {
694
+ e.IsCancelled = true;
695
+ }
696
+
697
+ foreach (var file in e.Files)
698
+ {
699
+ Console.WriteLine($"The user cleared this file before it was uploaded: {file.Name}");
700
+ }
701
+ }
702
+
703
+ // a sample way of generating the URLs to the endpoint
704
+ public string SaveUrl => ToAbsoluteUrl("api/upload/save");
705
+ public string RemoveUrl => ToAbsoluteUrl("api/upload/remove");
706
+
707
+ public string ToAbsoluteUrl(string url)
708
+ {
709
+ return $"{NavigationManager.BaseUri}{url}";
710
+ }
711
+ }
712
+ ````
668
713
669
714
670
715
## See Also
You can’t perform that action at this time.
0 commit comments