New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Required Field Validation

RadUpload has been replaced by RadAsyncUpload, Telerik’s next-generation ASP.NET upload component. If you are considering Telerik’s Upload control for new development, check out the documentation of RadAsyncUpload or the control’s product page. If you are already using RadUpload in your projects, you may be interested in reading how easy the transition to RadAsyncUpload is and how you can benefit from it in this blog post. The official support for RadUpload has been discontinued in June 2013 (Q2’13), although it is still be available in the suite. We deeply believe that RadAsyncUpload can better serve your upload needs and we kindly ask you to transition to it to make sure you take advantage of its support and the new features we constantly add to it.

Sometimes you might want to implement required field validation against the RadUpload control. That is to ensure that at least one file is uploaded on the server.

To accomplish this, we will use a custom validator.

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

Here is the client validation function of the validator:

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;

Here is the server validation function of the validator:

private void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs e)
    е.IsValid = (RadUpload1.InvalidFiles.Count == 0);

Private Sub CustomValidator1_ServerValidate( _
     ByVal source As Object, _
     ByVal e As ServerValidateEventArgs) _
     Handles Customvalidator1.ServerValidate
    е.IsValid = (RadUpload1.InvalidFiles.Count = 0)
End Sub

See Also

In this article