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

[Solved] validateExtensions error

1 Answer 142 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Jennifer
Top achievements
Rank 1
Jennifer asked on 15 Apr 2009, 03:21 PM
I'm having trouble getting client side validation of file extensions to work.  I have a page where users can upload a single file using the RadUpload control. I'm trying to use the validateExtensions function to validate the file extension.  I believe my code matches the example in your documentation but I am getting the javascript error "'null' is null or not an object" whenever validateExtensions is called.   If I hardcode true or false in place of my call to validateExtensions then I don't get the javascript error.  Below is my code.  

 

 

<%@ Page Language="VB" MasterPageFile="~/HBC_MP.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="data_transfer_upload_Default" title="File Transfer Admin Detail" Theme="MainTheme" %> 
<%@ Register Assembly="RJS.Web.WebControl.PopCalendar" Namespace="RJS.Web.WebControl" TagPrefix="rjs" %> 
<%@ Register TagPrefix="rad" Namespace="Telerik.WebControls" Assembly="RadUpload.Net2" %> 
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">  
<div id="container_middle"  class="clearfix" style="background-color:#eeeeee">   
<div id="content" style="width:910px">  
            <table style="width:100%">  
                <tr> 
                    <td> 
                                <h1 class="brand" style="width:600px;BACKGROUND-color: #eee;BORDER-LEFT: 0px;BORDER-RIGHT: 0px;text-transform:none;float:left;">  
                Data Transfer - File Upload  
            </h1> 
                    </td> 
                    <td style="vertical-align:middle;text-align:right">  
                              <asp:HyperLink ID="linkDownload" runat="server"  NavigateUrl="~/data_transfer/Default.aspx"  Font-Size="11.3px" Font-Underline="true">Download Files</asp:HyperLink> 
            
                    </td> 
                </tr> 
            </table> 
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
<br \> 
        <script type="text/javascript">  
            function increasingFileInputWidth(radUpload, args)  
            {  
             //If the Checkboxes in RadUpload are not visible, change the index to 0  
                var cell = args.Row.cells[0];  
                var inputs = cell.getElementsByTagName('INPUT');  
                for (var i=0; i<inputs.length; i++)  
                {  
                    if (inputs[i].type == "file")  
                    {  
                        inputs[i].size = 75;  
                    }  
                }  
            }  
        </script> 
 
<table align="Center">  
<tr> 
    <td> 
 
<table class="tablenav" align="left" border="0" cellpadding="0" cellspacing="0" style="margin-top:10px;margin-left:0px;margin-bottom:0px;width:750px;">  
    <tr> 
        <td align="right" valign="middle">  
        <rad:radprogressmanager id="Radprogressmanager1" runat="server" /> 
        </td> 
        <td valign="middle" colspan="3">  
            <asp:Label ID="lblMsg" runat="server" ForeColor="Red"></asp:Label> 
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Please Correct the Following"/>  
        </td> 
    </tr> 
    <tr style="height:23px">  
        <td align="right" valign="middle" style="height: 23px">  
            <asp:Label ID="lblCurrentFile" runat="server" Text="Currently Loaded File Name:"></asp:Label></td>  
        <td valign="middle" style="height: 23px" colspan="3">  
            <asp:Label ID="lblCurrentFileData" runat="server" EnableTheming="False"></asp:Label></td>  
    </tr> 
    <tr style="height:23px">  
 
        <td valign="middle" align="right" style="height: 23px">  
            <asp:Label ID="lblFile" runat="server" Text="Choose File:"></asp:Label></td>  
        <td valign="middle" style="height: 23px;padding-left: 2px" colspan="3">  
            &nbsp;&nbsp;Files can not be larger than 50MB  
            <rad:radupload   
                id="RadUpload1"   
                runat="server" MaxFileInputsCount="1" ControlObjectsVisibility="None" OnClientAdded="increasingFileInputWidth" EnableFileInputSkinning="False" Skin="Default" 
                 AllowedFileExtensions=".doc,.ppt,.xls,.pdf,.jpg,.jpeg,.gif,.txt,.avi,.dxf,.tif,.tiff" /> 
            <rad:radprogressarea id="progressArea1" runat="server" ProgressIndicators="TotalProgressBar, TotalProgress, TotalProgressPercent, RequestSize, TimeElapsed, TimeEstimated, TransferSpeed" Skin="HBC"></rad:radprogressarea> 
<asp:CustomValidator runat="server" id="CustomValidator1" 
  ClientValidationFunction="validateRadUpload1" 
  OnServerValidate="CustomValidator1_ServerValidate" ErrorMessage="Invalid File Extension." Display="None"></asp:CustomValidator> 
        <script type="text/javascript">  
 function validateRadUpload1(source, arguments)  
 {  
   arguments.IsValid = $find("<%=RadUpload1.ClientID%>").validateExtensions();  
 }  
</script>   
        </td> 
 
    </tr> 
    <tr style="height:23px">  
        <td align="right">  
            <asp:Label ID="lblFileDesc" runat="server" Text="File Description:"></asp:Label> 
        </td> 
        <td colspan="3">  
            <asp:TextBox ID="txtFileDesc" runat="server" Width="513px"></asp:TextBox> 
            <asp:RequiredFieldValidator ID="rfvFileDesc" runat="server" ControlToValidate="txtFileDesc" 
                ErrorMessage="File Description is Required." >*</asp:RequiredFieldValidator></td>  
    </tr> 
    </table> 
 <br /> 
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">  
                <ContentTemplate> 
                <table class="tablenav" align="left" border="0" cellpadding="0" cellspacing="0" style="margin-top:10px;margin-left:0px;margin-bottom:0px;width:750px;">  
    <tr style="height:23px">  
        <td align="right"  style="width:110px">  
            <asp:Label ID="lblCategory" runat="server" Text="Category:"></asp:Label> 
        </td> 
        <td style="width:215px">  
            <asp:DropDownList ID="ddlCategory" runat="server">  
            </asp:DropDownList> 
            <asp:Label ID="lblNoCategory" runat="server" Text="N/A" EnableTheming="False"></asp:Label> 
        </td> 
        <td align="left" > 
            <asp:Label ID="lblFileType" runat="server" Text="File Type:"></asp:Label> 
        </td> 
        <td> 
            <asp:DropDownList ID="ddlFileType" runat="server" AutoPostBack="True">  
            </asp:DropDownList> 
        </td> 
    </tr> 
 
    </table> 
    </ContentTemplate> 
    </asp:UpdatePanel> 
<br /> 
<table class="tablenav" align="left" border="0" cellpadding="0" cellspacing="0" style="margin-top:10px;margin-left:0px;margin-bottom:0px;width:750px;">  
                        <tr> 
                            <td style="width:110px">&nbsp;</td> 
                            <td colspan="3">  
                                <asp:Button ID="btnSave" runat="server" Text="Upload File" CssClass="button100" /> 
                            </td> 
                        </tr> 
                      </table> 
      
    </td> 
</tr> 
</table> 
<br /> 
 
<hr /> 
 
</asp:Content> 
 

 

 

 



1 Answer, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 17 Apr 2009, 02:55 PM
Hi Jennifer,

The validateExtensions method of the RadUpload client object returns true in there is no selected file, i.e. if you press the submit button before selecting a file. Otherwise is should work. I suggest you to use the following code in order to validate the upload both for extensions and for empty file name:

<script type="text/javascript"
            function validate(sender, e) { 
 
                e.IsValid = false
 
                var upload = $find("<%=RadUpload1.ClientID %>"); 
                var inputs = upload.getFileInputs() 
 
                for (var i = 0; i != inputs.length; i++) { 
                    if (inputs[i].value != "" && 
                                        upload.isExtensionValid(inputs[i])) { 
 
                        e.IsValid = true
                        break
                    } 
                } 
                e.IsValid = $find("<%=RadUpload1.ClientID%>").validateExtensions(); 
 
 
            } 
        </script>    


Kind regards,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Upload (Obsolete)
Asked by
Jennifer
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Share this question
or