RadUpload for ASP.NET

Client-Side Validation Send comments on this topic.
See Also
Uploading Files > RadUpload > Client-Side Validation

Glossary Item Box

Client-side ValidateExtensions() function

RadUpload provides the ValidateExtensions client-side function for file extension validation on the client. The validation is done by integrating the RadUpload with a CustomValidator.

The CustomValidator will prevent the page from submitting when there are selected files with invalid extensions. If the validator must be activated on the server, you must handle its ServerValidate event and perform the same validation again.

NOTE: The ControlToValidate property of the CustomValidator must not be set!

Important notes

The ControlToValidate property of the CustomValidator must not be set.

The selected files must be transferred to the server in order to be validated for size or mime-type. The file extensions can be validated on the client, before the upload.

To enable uploading of files, larger than 4MB, you must set the maxRequestLength attribute of the httpRuntime section in your web.config file.

Example:

The following example demonstrates how to validate extensions of the selected files client-side and server-side.

ASPX

<rad:radupload id="RadUpload1" runat= "server"
    allowedfileextensions= ".zip,.jpg,.jpeg" />
<asp:customvalidator 
runat="server" id="CustomValidator1" 
    display="Dynamic"
    clientvalidationfunction="ValidateRadUpload1"
    onservervalidate="CustomValidator1_ServerValidate">
        Invalid extensions.
</asp:customvalidator>

<asp:button runat="server" id="Button1" text="Submit" />
<script type="text/javascript">
function ValidateRadUpload1(source, arguments)
{
    arguments.IsValid = GetRadUpload('<%= RadUpload1.ClientID %>').ValidateExtensions();
}
</script>

VB.NET 

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

C#

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

See Also