RadUpload validation

Posted by Community Admin on 03-Aug-2018 21:04

RadUpload validation

All Replies

Posted by Community Admin on 14-May-2011 00:00

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

Posted by Community Admin on 15-May-2011 00:00

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);

Hope this helps.

This thread is closed