Edit this page

Client-side Validation

caution

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.

You can use RadUpload with an ASP.NET custom validator. CustomValidator supports both client-side and server-side validation.

  • Validating client-side has the advantage that the CustomValidator prevents the page from submitting when there are selected files that the client-side validation function considers invalid.The validation function can use the validateExtensions() client-side method to validate file extensions on the client.
note

Selected files must be transferred to the server before they can be validated for size or mime-type .

  • Validating server-side has the advantage that you can access file information such as size or mime-type, or even examine the file contents. The custom validator's ServerValidate event occurs after the RadUpload ValidatingFile event and any integrated validation.
caution

When using RadUpload with a CustomValidator , the validator's ControlToValidate property must not be set!

Example

The following example demonstrates using RadUpload with a custom validator to validate the extensions of selected files both client-side and server-side.

<telerik:radupload id="RadUpload1" runat="server" allowedfileextensions=".zip,.jpg,.jpeg" />

<asp:CustomValidator runat="server" ID="CustomValidator1" Display="Dynamic" ClientValidationFunction="validateRadUpload1"
    OnServerValidate="CustomValidator1_ServerValidate">        
    Invalid extension.
</asp:CustomValidator>

<asp:Button runat="server" ID="Button1" Text="Submit" />

<script type="text/javascript">
    function validateRadUpload1(source, arguments) {
        arguments.IsValid = $find("<%= RadUpload1.ClientID %>").validateExtensions();
    }
</script>

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