This is a migrated thread and some comments may be shown as answers.

RadAsyncUpload get value MaxFileSize client side

4 Answers 119 Views
Window
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 2
Erik asked on 16 Nov 2013, 06:28 PM
Hello,

Seems simple, but how do I get the MaxFileSize client side? I've created a standard JS function for validation:
function OnClientValidationFailed(sender, args) {
    try {
        var fileExtention = args.get_fileName().substring(args.get_fileName().lastIndexOf('.') + 1, args.get_fileName().length);
        if (args.get_fileName().lastIndexOf('.') != -1) {//this checks if the extension is correct
            if (sender.get_allowedFileExtensions().indexOf(fileExtention) == -1) { //alert("Wrong Extension!");
                var msg = 'The file upload has failed because this is not an allowed extension. Allowed extensions are {0}.';
                msg = msg.replace("{0}", sender.get_allowedFileExtensions());
                radalert(msg, 400, 200, 'The file upload has failed.', null, null);
            }
            else { //alert("Wrong file size!");
                var msg = 'The file upload has failed because the file is to large. Maximum file size allowed is {0} Kb.'
                msg = msg.replace("{0}", 4096000 / 1024);
                radalert(msg, 400, 200, 'The file upload has failed.', null, null);
            }
        }
        else { //alert("not correct extension!");
          var msg = 'The file upload has failed because this is not an allowed extension. Allowed extensions are {0}.';
            msg = msg.replace("{0}", sender.get_allowedFileExtensions());
            radalert(msg, 400, 200, 'The file upload has failed.', null, null);
        }
    }
    catch (ex) {
        alert("JS Error #1311161741:" + ex);
    }
    setTimeout(function () { sender.deleteFileInputAt(0); }, 10);
}

(Hope it helps others)
I thought it useful to inform the user that not only the file is to large, but also what the maximum file size is. Since this is a function that is used for many purposes, I want the function to retrieve something like: sender."get_maxFileSize"? So, get the MaxFileSize via the sender.

Thanks in advance,

Erik

4 Answers, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 20 Nov 2013, 03:22 PM
Hello Erik,

To get the needed value you can use either of the following two lines of code:
sender.get_maxFileCount();
//or
sender._maxFileSize;


Regards,
Kate
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Erik
Top achievements
Rank 2
answered on 20 Nov 2013, 04:24 PM
Thank you Kate, this is working fine.

Just out of curiosity: is there anywhere I can find this kind of information myself?
0
Shinu
Top achievements
Rank 1
answered on 21 Nov 2013, 03:52 AM
Hi Erik,

Please check this documentation on RadAsyncUpload Client Object which lists the client side methods of the control.

Hope this helps,
Shinu.
0
Kate
Telerik team
answered on 21 Nov 2013, 11:35 AM
Hello Erik,

You can use our on-line documentation as Shinu suggested and you can also check out the following blog post where it is described in details how you can find out any of the methods and properties that are used in the code of the control - http://www.sitefinitysteve.com/articles/clientside-debugging.

Regards,
Kate
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Window
Asked by
Erik
Top achievements
Rank 2
Answers by
Kate
Telerik team
Erik
Top achievements
Rank 2
Shinu
Top achievements
Rank 1
Share this question
or