Checking File Size on the Client

Thread is closed for posting
13 posts, 1 answers
  1. Mina
    Mina avatar
    8 posts
    Member since:
    Feb 2008

    Posted 03 Mar 2010 Link to this post

    I read this page, and I wrote the program.
    But "args.get_progressData().RadUpload.RequestSize" is undefined.
    Please teach the correction method.

    <rad:RadScriptManager ID="RadScriptManager1" runat="server">  
    </rad:RadScriptManager> 
     
    <script type="text/javascript" > 
        if (!progressArea.confirmed &&  
           args.get_progressData().RadUpload.RequestSize > 1000000)  
       {  
         if (confirm("The total size of the selected files" +  
                     " is more than the limit." +  
                     " Do you want to cancel the upload?"))  
         {  
            progressArea.cancelRequest();  
         }  
         else  
         {  
            progressArea.confirmed = "confirmed";  
         }  
       }  
    </script> 
     
    <rad:RadProgressManager ID="RadProgressManager1" runat="server" /> 
    <rad:RadUpload ID="rupDocTempFile" runat="server" Skin="Telerik"></rad:RadUpload> 
    <rad:RadProgressArea ID="RadProgressArea1" runat="server" OnClientProgressUpdating="checkUploadedFilesSize">  
    </rad:RadProgressArea> 
     
    <asp:Button ID="btnSave" runat="server" Text="SAVE" OnClick="btnSave_Click" AccessKey="v" ToolTip="Save(v)" /> 
  2. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 03 Mar 2010 Link to this post

    The reason it doesn't work is because you didn't enclose it inside the function called checkUploadedFileSize, which you associated with the RadProgessArea control.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mina
    Mina avatar
    8 posts
    Member since:
    Feb 2008

    Posted 03 Mar 2010 Link to this post

    Thank you for your Reply, robertw102 .
    I change program, but "args.get_progressData().RadUpload.RequestSize" is undefined.
    What's wrong with program?

    <rad:RadScriptManager ID="RadScriptManager1" runat="server">     
    </rad:RadScriptManager>    
        
    <script type="text/javascript" >    
       function checkUploadedFilesSize(progressArea, args)  
       {  
          if (!progressArea.confirmed &&     
              args.get_progressData().RadUpload.RequestSize > 1000000)     
         {     
            if (confirm("The total size of the selected files" +     
                     " is more than the limit." +     
                     " Do you want to cancel the upload?"))     
           {     
              progressArea.cancelRequest();     
            }     
            else     
            {     
               progressArea.confirmed = "confirmed";     
             }     
          }   
        }   
    </script>    
        
    <rad:RadProgressManager ID="RadProgressManager1" runat="server" />    
    <rad:RadUpload ID="rupDocTempFile" runat="server" Skin="Telerik"></rad:RadUpload>    
    <rad:RadProgressArea ID="RadProgressArea1" runat="server" OnClientProgressUpdating="checkUploadedFilesSize">     
    </rad:RadProgressArea>    
        
    <asp:Button ID="btnSave" runat="server" Text="SAVE" OnClick="btnSave_Click" AccessKey="v" ToolTip="Save(v)" /   
     
  5. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 04 Mar 2010 Link to this post

    Maybe instead of using RequestSize to use RequestLength. I looked at the Telerik documentation on the ProgressData client object and the RequestSize property doesn't exists, but RequestLength. I'm guessing there the same thing.

    Tell me if that works.
  6. Mina
    Mina avatar
    8 posts
    Member since:
    Feb 2008

    Posted 04 Mar 2010 Link to this post

    Thank you for your Reply, robertw102 .
    I change program, but "args.get_progressData().RadUpload.RequestLength" is undefined.
    Also , I  wrote this proguram.

    <rad:RadScriptManager ID="RadScriptManager1" runat="server">        
    </rad:RadScriptManager>       
           
    <script type="text/javascript" >       
       function checkUploadedFilesSize(progressArea, args)     
       {     
          alert(args.get_progressData());  
          alert(args.get_progressData().RadUpload);  
          alert(args.get_progressData().RadUpload.RequestLength);  
          if (!progressArea.confirmed &&        
              args.get_progressData().RadUpload.RequestLength > 1000000)        
         {        
            if (confirm("The total size of the selected files" +        
                     " is more than the limit." +        
                     " Do you want to cancel the upload?"))        
           {        
              progressArea.cancelRequest();        
            }        
            else        
            {        
               progressArea.confirmed = "confirmed";        
             }        
          }      
        }      
    </script>       
           
    <rad:RadProgressManager ID="RadProgressManager1" runat="server" />       
    <rad:RadUpload ID="rupDocTempFile" runat="server" Skin="Telerik"></rad:RadUpload>       
    <rad:RadProgressArea ID="RadProgressArea1" runat="server" OnClientProgressUpdating="checkUploadedFilesSize">        
    </rad:RadProgressArea>       
           
    <asp:Button ID="btnSave" runat="server" Text="SAVE" OnClick="btnSave_Click" AccessKey="v" ToolTip="Save(v)" /> 
    " args.get_progressData()" is object.
    But "args.get_progressData().RadUpload" is undefined.

    Please advice, thx.
  7. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 05 Mar 2010 Link to this post

    Does your page include the required web.config declarations for using RadProgressManager and RadProgessArea in your application. Maybe that's the issue.
  8. Mina
    Mina avatar
    8 posts
    Member since:
    Feb 2008

    Posted 07 Mar 2010 Link to this post

    Thank you for your advice.
    I check this page.
    And I check web.config.
    I use IIS6.0, so web.config like this.

    <system.web> 
        <httpRuntime maxRequestLength="1012000" executionTimeout="3600"/>  
        <httpModules> 
            <add name="RadCompression" type="Telerik.Web.UI.RadCompression"/>  
            <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule" /> 
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
        </httpModules> 
        <httpHandlers> 
            <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false"/>  
            <add verb="*" path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler, Telerik.Web.UI, Culture=neutral, PublicKeyToken=121fae78165ba3d4"></add> 
            <add path="Telerik.RadUploadProgressHandler.ashx" verb="*" type="Telerik.Web.UI.RadUploadProgressHandler, Telerik.Web.UI" validate="false"/>  
            <remove verb="*" path="*.asmx"/>  
            <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
            <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
            <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>  
        </httpHandlers> 
    <system.web> 

    Is there something an insufficient element?
  9. Answer
    Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 08 Mar 2010 Link to this post

    Hello Mina,

    Your web.config looks completely correct. I am attaching working sample project that demonstrates the client-size validation approach.

    All the best,
    Genady Sergeev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  10. Mina
    Mina avatar
    8 posts
    Member since:
    Feb 2008

    Posted 12 Mar 2010 Link to this post

    Thank you for sample.
    I confirmed the sample.
    So, I change "OnClientProgressUpdating"  into "OnClientProgressBarUpdating".
    Then Program work.

    Thanks!
  11. Quan Nguyen
    Quan Nguyen avatar
    19 posts
    Member since:
    Jul 2009

    Posted 10 Jan 2011 Link to this post

    Hi,
    Should this validation method be working for older "non AJAX" of telerik ASP.NET radupload?

    Thanks
    Quan
  12. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 12 Jan 2011 Link to this post

    Hello Quan,

    I'm afraid that RadUpload for ASP.NET doesn't support client-side validation.

    All the best,
    Yana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  13. SlimSjakie
    SlimSjakie avatar
    10 posts
    Member since:
    Apr 2010

    Posted 03 Dec 2012 Link to this post

    I believe that it IS possible.

    1. Use a CustomValidator on your page like so:

    <asp:CustomValidator runat="server" ClientValidationFunction="valFileSize">File is Too Large!</asp:CustomValidator>


    2. Use the following javascript client function to check the file size:

    function valFileSize(source, arguments)
    {   
        var myFileSize = 0;
        var maxFileSize = 2048;
     
        var radUpload = getRadUpload('<%= ruNewFile.ClientID %>');
     
        var fileInputs = radUpload.getFileInputs();
     
        if (fileInputs && fileInputs.length > 0)
        {
            if (fileInputs[0].files) { myFileSize = fileInputs[0].files[0].size; }
            else if (fileInputs[0].document) { myFileSize = fileInputs[0].document.fileSize; } //<< IE8 --
        }
     
        arguments.IsValid = (myFileSize <= maxFileSize);  
    }

    the above example works only for a RadUpload control with 1 fileinput.
  14. Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 06 Dec 2012 Link to this post

    Hello,

     
    You can also consider using RadAsyncUpload instead of RadUpload for such validation as it is done in this on-line demo.

    You can also review this blog post that explains with several reasons why we recommend such change.

    All the best,
    Plamen
    the Telerik team
    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 their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017