Blank selected file field

Thread is closed for posting
2 posts, 0 answers
    STEPHEN avatar
    13 posts
    Member since:
    Sep 2010

    Posted 18 Nov 2010 Link to this post

    I have a button that uploads the selected file through RadInput.  However, if the user clicks it and the selected file input is blank it errors.  How can I check whether the RadInput is blank or null so I can send a custom error. Or can I hook it up to a validator? 
    STEPHEN avatar
    13 posts
    Member since:
    Sep 2010

    Posted 22 Nov 2010 Link to this post

    found it:

    1st a custom validator:
    <asp:CustomValidator runat="server" id="CustomValidator1"
    You have entered an invalid file. The file extension must be either XLS or XLSX! Please select another file!

    Then JavaScript

    <script type="text/javascript">
        function validateRadUploadNoBlanks(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;

    Then code behind on custom validator

    Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
           'add this to the custom validator along with the java script function validateRadUploadNoBlanks
           args.IsValid = RadUpload1.UploadedFiles.Count > 0
       End Sub

Back to Top