Hello,
I'm trying to set a customvalidator for the RadUpload control in order to check the maximum upload size, but I got an error (Attached screen-shot). My code is based on http://sample.topscms.com/blog/post/1607--client-side-file-size-validation-for-telerik-upload.
Default2.aspx:
Default2.aspx.cs:
Please, I need you help in order to solve this problem.
It is very appreciated to send me the modified code.
Regards,
Bader
I'm trying to set a customvalidator for the RadUpload control in order to check the maximum upload size, but I got an error (Attached screen-shot). My code is based on http://sample.topscms.com/blog/post/1607--client-side-file-size-validation-for-telerik-upload.
Default2.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
asp:ScriptManager
ID
=
"asdasD"
runat
=
"server"
>
</
asp:ScriptManager
>
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
var currentLoadingPanel = null;
var currentUpdatedControl = null;
function RequestStart(sender, args) {
currentLoadingPanel = $find("<%= TasksRadAjaxLoadingPanel.ClientID %>");
if (args.get_eventTarget() == "<%= SubmitButton.UniqueID %>") {
args.set_enableAjax(false);
}
currentUpdatedControl = "<%= MainPanel.ClientID %>";
//show the loading panel over the updated control
currentLoadingPanel.show(currentUpdatedControl);
}
function ResponseEnd() {
//hide the loading panel and clean up the global variables
if (currentLoadingPanel != null)
currentLoadingPanel.hide(currentUpdatedControl);
currentUpdatedControl = null;
currentLoadingPanel = null;
}
function validateRadUploadFileSize(source, arguments) {
var totalFileSize = 0;
var maxFileSize = 100000;
var radUpload = $find('<%= AttachedFilesRadUpload.ClientID %>');
var fileInputs = radUpload.getFileInputs();
for (var i in fileInputs) {
if (fileInputs[i] && fileInputs[i].files[0]) {
totalFileSize += fileInputs[i].files[0].fileSize;
}
}
arguments.IsValid = totalFileSize <= maxFileSize;
}
</
script
>
</
telerik:RadCodeBlock
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"SubmitButton"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"MainPanel"
LoadingPanelID
=
"TasksRadAjaxLoadingPanel"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
<
ClientEvents
OnRequestStart
=
"RequestStart"
OnResponseEnd
=
"ResponseEnd"
/>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
ID
=
"TasksRadAjaxLoadingPanel"
Skin
=
"Vista"
runat
=
"server"
>
</
telerik:RadAjaxLoadingPanel
>
<
asp:Panel
ID
=
"MainPanel"
Width
=
"100%"
HorizontalAlign
=
"Left"
runat
=
"server"
>
<
telerik:RadProgressManager
ID
=
"Radprogressmanager1"
Width
=
"403px"
runat
=
"server"
/>
<
telerik:RadUpload
ID
=
"AttachedFilesRadUpload"
InitialFileInputsCount
=
"1"
MaxFileInputsCount
=
"10"
ControlObjectsVisibility
=
"AddButton, RemoveButtons, CheckBoxes"
Width
=
"405px"
runat
=
"server"
/>
<
telerik:RadProgressArea
runat
=
"server"
Width
=
"405px"
ID
=
"ProgressArea1"
></
telerik:RadProgressArea
>
<
asp:CustomValidator
runat
=
"server"
ID
=
"CustomValidator1"
Display
=
"Dynamic"
ClientValidationFunction
=
"validateRadUploadFileSize"
OnServerValidate
=
"CustomValidator1_ServerValidate"
ValidationGroup
=
"CreateNewTaskValidationGroup"
>
The maximum upload size is 100 KB
</
asp:CustomValidator
>
<
asp:Button
runat
=
"server"
ID
=
"SubmitButton"
ValidationGroup
=
"CreateNewTaskValidationGroup"
Text
=
"Submit"
/>
</
asp:Panel
>
</
div
>
</
form
>
</
body
>
</
html
>
Default2.aspx.cs:
using System;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = (AttachedFilesRadUpload.InvalidFiles.Count == 0);
}
}
Please, I need you help in order to solve this problem.
It is very appreciated to send me the modified code.
Regards,
Bader