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

Checking File Size on the Client

12 Answers 242 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Mina
Top achievements
Rank 1
Mina asked on 03 Mar 2010, 08:00 AM
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)" /> 

12 Answers, 1 is accepted

Sort by
0
robertw102
Top achievements
Rank 1
answered on 03 Mar 2010, 07:29 PM
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.
0
Mina
Top achievements
Rank 1
answered on 04 Mar 2010, 12:40 AM
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)" /   
 
0
robertw102
Top achievements
Rank 1
answered on 04 Mar 2010, 09:02 PM
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.
0
Mina
Top achievements
Rank 1
answered on 05 Mar 2010, 02:40 AM
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.
0
robertw102
Top achievements
Rank 1
answered on 05 Mar 2010, 04:32 PM
Does your page include the required web.config declarations for using RadProgressManager and RadProgessArea in your application. Maybe that's the issue.
0
Mina
Top achievements
Rank 1
answered on 08 Mar 2010, 01:32 AM
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?
0
Accepted
Genady Sergeev
Telerik team
answered on 08 Mar 2010, 04:40 PM
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.
0
Mina
Top achievements
Rank 1
answered on 12 Mar 2010, 06:41 AM
Thank you for sample.
I confirmed the sample.
So, I change "OnClientProgressUpdating"  into "OnClientProgressBarUpdating".
Then Program work.

Thanks!
0
Quan Nguyen
Top achievements
Rank 1
answered on 10 Jan 2011, 07:40 PM
Hi,
Should this validation method be working for older "non AJAX" of telerik ASP.NET radupload?

Thanks
Quan
0
Yana
Telerik team
answered on 12 Jan 2011, 09:38 AM
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.
0
SlimSjakie
Top achievements
Rank 2
answered on 03 Dec 2012, 10:55 AM
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.
0
Plamen
Telerik team
answered on 06 Dec 2012, 09:08 AM
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.
Tags
Upload (Obsolete)
Asked by
Mina
Top achievements
Rank 1
Answers by
robertw102
Top achievements
Rank 1
Mina
Top achievements
Rank 1
Genady Sergeev
Telerik team
Quan Nguyen
Top achievements
Rank 1
Yana
Telerik team
SlimSjakie
Top achievements
Rank 2
Plamen
Telerik team
Share this question
or