File validation does not work for me!

2 posts, 0 answers
  1. elaheh
    elaheh avatar
    7 posts
    Member since:
    Oct 2010

    Posted 03 Jul 2012 Link to this post

    Hi,
    I have tried to use the codes are for validation in Asyncupload and uplod tools in these links:
    http://demos.telerik.com/aspnet-ajax/upload/examples/async/validation/defaultcs.aspx?product=asyncupload
    http://www.telerik.com/help/aspnet-ajax/upload-client-side-validation.html

    But none of them works correcrtly! when I select a non-valid file (for example a pdf file which its extension is changed to jpg), it does not prevent uploading it.

    this is all my code with Asyncupload:
    <asp:Content ID="Content2" ContentPlaceHolderID="content2" Runat="Server">
    <script type="text/javascript">
          //<![CDATA[
            function validationFailed(sender, eventArgs) {
                $(".ErrorHolder").append("<p>Validation failed for '" + eventArgs.get_fileName() + "'.</p>").fadeIn("slow");
            }
          //]]>
        </script>
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
        </telerik:RadStyleSheetManager>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI"
                    Name="Telerik.Web.UI.Common.Core.js">
                </asp:ScriptReference>
     
                <asp:ScriptReference Assembly="Telerik.Web.UI"
                    Name="Telerik.Web.UI.Common.jQuery.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI"
                    Name="Telerik.Web.UI.Common.jQueryInclude.js">
                </asp:ScriptReference>
            </Scripts>
        </telerik:RadScriptManager>
    <telerik:RadButton ID="uploadbtn" runat="server" Text="upload"
            onclick="uploadbtn_Click">
        </telerik:RadButton>
        <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server"
            AllowedFileExtensions="jpg,jpeg"
            TargetFolder="~/upload" OnClientValidationFailed="validationFailed"
            onfileuploaded="RadAsyncUpload1_FileUploaded" >
            <FileFilters>
            <telerik:FileFilter Description="Images(jpeg;jpg)" Extensions="jpeg,jpg" />
        </FileFilters>
        </telerik:RadAsyncUpload>

    and in code behind for upload button:
    protected void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
        {
            Label fileName = new Label();
            fileName.Text = e.File.FileName;
     
     
            if (e.IsValid)
            {
                Response.Write(fileName + "::true");
            }
            else
            {
                Response.Write("false");
            }
        }
     Is there anything missing from me?
  2. Plamen
    Admin
    Plamen avatar
    2729 posts

    Posted 04 Jul 2012 Link to this post

    Hi Elaheh,

     
    The validation is checking exactly the extension so if it is changed the expected behavior will be the file to be uploaded.

    Hope this will explain the issue.

    All the best,
    Plamen Zdravkov
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top