More in this section

Forums / General Discussions / RadUpload validation

RadUpload validation

2 posts, 1 answered
  1. John
    John avatar
    97 posts
    Registered:
    11 Jan 2011
    14 May 2011
    Link to this post

    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

  2. Vesko
    Vesko avatar
    4 posts
    Registered:
    09 Mar 2009
    15 May 2011
    Link to this post
    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.
    Answered
2 posts, 1 answered