RadAsyncUpload get value MaxFileSize client side

5 posts, 0 answers
  1. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 16 Nov 2013 Link to this post

    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
  2. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 20 Nov 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 20 Nov 2013 Link to this post

    Thank you Kate, this is working fine.

    Just out of curiosity: is there anywhere I can find this kind of information myself?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Nov 2013 Link to this post

    Hi Erik,

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

    Hope this helps,
    Shinu.
  6. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 21 Nov 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017