RadControls for ASP.NET AJAX
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 RadUploadValidatingFile 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.
CopyASPX
<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>
CopyC#
private void CustomValidator1_ServerValidate( object source, ServerValidateEventArgs e) {
е .IsValid = (RadUpload1.InvalidFiles.Count == 0);
}
CopyVB.NET
Private Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal e As ServerValidateEventArgs) Handles Customvalidator1.ServerValidate
е.IsValid = (RadUpload1.InvalidFiles.Count = 0)
End Sub
See Also