RadControls for ASP.NET AJAX
When validating selected files in client-side code, you can
only check the file extensions.
Information about the file sizes is not available on the client until files are uploaded. Once the upload begins, however,
RadProgressManager relays to RadProgressArea information from the sever,
including the combined file size.
While it is not possible to check the file size before upload begins, you can use the client-side OnClientProgressUpdating
event to access information about the file size when it first becomes available.
Note |
|---|
You may need to set maxRequestLength to a large value so that the user does not
get "Page not found" errors, which cannot be handled, when selecting very large files
|
The following example illustrates how to use OnClientProgressUpdating to check the size of uploaded files (in bytes) after
the upload process starts. This event occurs every time the RadProgressArea updates, so you need to use a custom
variable to flag when the check has already occurred.
Caution |
|---|
When the upload request is canceled, the page refreshes and all information entered in the RadUpload control is lost.
|
CopyASPX
<script type="text/javascript">
function checkUploadedFilesSize(progressArea, args) {
//progressArea.confirmed is a custom variable,
// you can use another if you want to
if (!progressArea.confirmed &&
args.get_progressData().RadUpload.RequestSize > 1000000) {
if (confirm("The total size of the selected files" +
" is more than the limit." +
" Do you want to cancel the upload?")) {
progressArea.cancelRequest();
}
else {
progressArea.confirmed = "confirmed";
}
}
}
</script>
<telerik:RadUpload runat="server" id="RadUpload1" />
<telerik:RadProgressArea runat="server" id="RadProgressArea1" OnClientProgressUpdating="checkUploadedFilesSize" />
<telerik:RadProgressManager runat="server" id="RadProgressManager1" />
<asp:Button runat="server" id="Button1" text="Upload" /> Caution |
|---|
The current mechanism for canceling a file upload sometimes does not notify the server for the performed action and the latter continues to
process the upload request. This often happens on Windows 2003 Server with a browser other than IE6. Furthermore, while the confirmation dialog is displayed, the form submission continues, which means that the file is still being uploaded. |
See Also