Skip to content

Commit 5b620de

Browse files
authored
Migrate the triaged code-libraries to new KB articles (#516)
* kb(grid): add article set 100% percent height when resizing closes telerik/telerik.web.ui#2087 * kb(grid): add article get selected items through all pages * kb(grid): add article integration with signalr * kb(grid): add article show progress bar on submit using asyncupload * kb(grid): add article inplace column edit * kb(grid): add article set grid height in percentage * kb(chart): add article add gap between donut chart segments * kb(combobox): add article combobox dropdown in input element * kb(common): add article add page transition animation * kb(grid): add article retain expanded form when rebinding * kb(grid): adjust article * kb(asyncupload): add article client side validation * kb(gantt): add article custom task edit window * kb(grid): add article copy paste cells/rows * kb(htmlchart): add article group datasource * kb(clientexportmanager): add article export multiple files * kb(clientexportmanager): add article page for client-side export * kb(ziplibrary): add article download multiple files * kb(grid): add article manual crud with auto generated editform * kb(combobox): add article filter with checkboxes * kb(grid): add article display-group-name * kb(grid): add article "Check All" to include only displayed list * kb(grid): add missing slug * kb(grid): add article lazy loading/infinite scroll * kb(dropdownlist): add article dropdown with free text Other field * kb(grid): add article show loading panel on export * kb(binaryimage): add article display fuill image on hover/click * kb(toolbar): add article perform a postback from callback * kb(grid): add article export to pdf/excel image header * kb(grid): add article export hierarchical grid * kb(scheduler): add article convert recurrence rule to descriptive text * kb(grid): add article export hierarchical grid with grouping * kb(listbox): add article client-side filtering * kb(grid): add article export multiple grids * docs(common): add article call radconfirm from code behind * kb(common): add article skin exchange * kb(treeview): add article filter treeview * kb(common): add article eu cookie consent * kb(grid): add article export html into .docx * kb(spreadsheet): add article database provider * kb(datepicker): add article change default culture * kb(grid): add article databinding with web API * kb(editor): add article independent files manger * kb(gantt): add article custom columns * kb(common): add article custom membership and roles * kb(grid): add article batch editing extensions * kb(grid): add article radibutton check at a time * kb(grid): add article load on demand combobox * kb(common): add article redirect after session expiration * kb(htmlchart): add article export to png and pdf * kb(grid): add article get file path to uploaded file * kb(editor): add article mailmerge * kb(clientexportmanager): add article save file with webAPI * kb(grid): add article crud with stored precedures * kb(editor): add article upload zip file and unzip content * kb(common): add article connnect editor/fe to sql server * kb(datepicker): add article disable days * kb(common): add article localization
1 parent a32d037 commit 5b620de

File tree

143 files changed

+12983
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+12983
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
title: Client-Side file size validation
3+
description: Client-Side file size validation. Check it now!
4+
type: how-to
5+
page_title: Client-Side file size validation. | RadAsyncUpload
6+
slug: asyncupload-client-side-file-size-validation
7+
res_type: kb
8+
tags: asyncupload, validation, client side validation, async upload client side validation, telerik, telerik ajax
9+
---
10+
11+
## Environment
12+
13+
<table>
14+
<tbody>
15+
<tr>
16+
<td>Product</td>
17+
<td>Telerik WebForms AsyncUpload for ASP.NET AJAX</td>
18+
</tr>
19+
</tbody>
20+
</table>
21+
22+
## Description
23+
24+
The aim of the article is to gain some kind of client side validation to restrict users from adding more than a pre-determined limit of files based upon total size of all uploaded files, not just each file or number of files.
25+
26+
## Solution
27+
28+
This JavaScript code enforces client-side validation to prevent users from uploading more files than a preset limit based on the total size of all files uploaded, handling duplicate file detection and exceeding total size limits while providing real-time feedback during the upload process.
29+
30+
````ASP.NET
31+
<table>
32+
<tr>
33+
<td colspan="2">You may attach up to 20mb in files to the Email.</td>
34+
</tr>
35+
<tr>
36+
<td>Select File(s):</td>
37+
<td>
38+
<telerik:RadAsyncUpload ID="RadAsyncUpload1"
39+
OnClientFileSelected="OnFileSelected"
40+
OnClientFileUploadFailed="OnFileUploadFailed"
41+
OnClientFilesUploaded="OnFilesUploaded"
42+
OnClientProgressUpdating="OnProgressUpdating"
43+
OnClientFileUploaded="OnFileUploaded"
44+
OnClientFileUploadRemoved="OnFileUploadRemoved"
45+
runat="server">
46+
</telerik:RadAsyncUpload>
47+
</td>
48+
</tr>
49+
</table>
50+
````
51+
52+
````JavaScript
53+
var uploadsInProgress = 0;
54+
var MAX_TOTAL_BYTES = 20971520;
55+
var filesSize = new Array();
56+
var OVERSIZE_MESSAGE = "You are only allowed to add up to 20mb of files total";
57+
var isDuplicateFile = false;
58+
59+
function OnFileSelected(sender, args) {
60+
for (var fileindex in sender._uploadedFiles) {
61+
if (sender._uploadedFiles[fileindex].fileInfo.FileName == args.get_fileName()) {
62+
isDuplicateFile = true;
63+
}
64+
}
65+
66+
if (!uploadsInProgress) {
67+
$("input[id$=btnSave]").attr("disabled", "disabled");
68+
}
69+
uploadsInProgress++;
70+
}
71+
72+
function OnFilesUploaded(sender, args) {
73+
if (sender._uploadedFiles.length == 0) {
74+
filesSize = new Array();
75+
uploadsInProgress = 0;
76+
$("input[id$=btnSave]").removeAttr("disabled");
77+
}
78+
79+
if (uploadsInProgress > 0) {
80+
DecrementUploadsInProgress();
81+
}
82+
}
83+
84+
function OnProgressUpdating(sender, args) {
85+
filesSize[args.get_data().fileName] = args.get_data().fileSize;
86+
}
87+
88+
function OnFileUploadFailed(sender, args) {
89+
DecrementUploadsInProgress();
90+
}
91+
92+
function OnFileUploaded(sender, args) {
93+
DecrementUploadsInProgress();
94+
var totalBytes = 0;
95+
var numberOfFiles = sender._uploadedFiles.length;
96+
97+
if (isDuplicateFile) {
98+
sender.deleteFileInputAt(numberOfFiles - 1);
99+
isDuplicateFile = false;
100+
sender.updateClientState();
101+
alert("You can't add the same file twice");
102+
return;
103+
}
104+
105+
for (var index in filesSize) {
106+
totalBytes += filesSize[index];
107+
}
108+
109+
if (totalBytes > MAX_TOTAL_BYTES) {
110+
sender.deleteFileInputAt(numberOfFiles - 1);
111+
sender.updateClientState();
112+
alert(OVERSIZE_MESSAGE);
113+
}
114+
}
115+
116+
function OnFileUploadRemoved(sender, args) {
117+
if (args.get_fileName() != null) {
118+
if (!isDuplicateFile) {
119+
delete filesSize[args.get_fileName()];
120+
}
121+
}
122+
}
123+
124+
function DecrementUploadsInProgress() {
125+
uploadsInProgress--;
126+
if (!uploadsInProgress) {
127+
$("input[id$=btnSave]").removeAttr("disabled");
128+
}
129+
}
130+
````
131+
132+

0 commit comments

Comments
 (0)