RadUpload validation
Hi
I have a RADUpload in a widget (ascx file). How can I implement client side validation for RadUpload so user is compelled to provide a file name for upload?
Thanks
Regards
You can try the following:
<
telerik:radupload
id
=
"RadUpload1"
initialfileinputscount
=
"3"
allowedfileextensions
=
".txt"
targetfolder
=
"~/uploads"
runat
=
"server"
></
telerik:radupload
>
<
asp:CustomValidator
ID
=
"CustomValidator1"
runat
=
"server"
ClientValidationFunction
=
"validateRadUpload"
ErrorMessage
=
"Please select at least one Text file"
OnServerValidate
=
"CustomValidator1_ServerValidate"
></
asp:CustomValidator
>
function
validateRadUpload(source, e)
e.IsValid =
false
;
var
upload = $find(
"<%= RadUpload1.ClientID %>"
);
var
inputs = upload.getFileInputs();
for
(
var
i = 0; i < inputs.length; i++)
//check for empty string or invalid extension
if
(inputs[i].value !=
""
&& upload.isExtensionValid(inputs[i].value))
e.IsValid =
true
;
break
;
private
void
CustomValidator1_ServerValidate(
object
source, ServerValidateEventArgs e)
е.IsValid = (RadUpload1.InvalidFiles.Count == 0);