I have a custom handler that I am using to encrypt and store uploaded tiff files to a database. I want to add validation that would check the file to see if it is corrupt before saving. How do I send an error message back to the client?
CustomAsyncUploadResult result = CreateDefaultUploadResult<CustomAsyncUploadResult>(file);
//file.SaveAs(targetFolder + "/" + fileName);
if (true)
{
//Success
result.ErrorMessage = String.Empty;
}
else
{
// Error. Set error message
result.ErrorMessage = "File failed to upload in DB";
}
return result;
}
and then handle it on the client in OnClientFileUploaded event:
function OnClientFileUploaded(sender, args) {
var msg = args.get_fileInfo().ErrorMessage;
if (msg) {
//Display error message
$('#msg').text(msg);
//Remove selected file
$('.ruButton.ruRemove').click();
}
}
For your reference I'm attaching small sample demonstrating how this code works. Additionally you could take a look at this online demo which implements the same approach.
Kind regards,
Hristo Valyavicharski
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.