Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

Upload / Keyboard Support



  • Keep in mind:

    • When using access key functionality the AccessKey property of RadUpload control should be set to a capital letter.
    • Notice that in Opera browser to focus file input you need to Tab twice. This apply only in case when using RadUpload control without checkboxes.

    AccessKey = "P"

    Note: The largest allowed combined file size for upload in this example is 100MB. This is specified by the maxRequestLength="102400" set in Web.config file. If you attempt to upload files with total size greater that 100MB you will get "Page Not Found" error. For more information about uploading large files visit the help article Uploading Large Files

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="c#" CodeFile="DefaultCS.aspx.cs" AutoEventWireup="true" Inherits="Telerik.Web.Examples.Upload.IntegratedValidation.DefaultCS" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag runat="server" ID="Headtag1"></qsf:HeadTag>
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
        <telerik:RadScriptManager ID="ScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <qsf:Header runat="server" ID="Header1" NavigationLanguage="C#"></qsf:Header>
        <telerik:RadUpload runat="server" ID="RadUpload" OnClientAdded="keyboardSupport"
            AccessKey="P">
        </telerik:RadUpload>
        <br />
        <telerik:RadButton runat="server" ID="RadButton" Text="Submit">
        </telerik:RadButton>
        <qsf:Footer runat="server" ID="Footer1"></qsf:Footer>
        </form>
        <script type="text/javascript">

            $ = $telerik.$;

            // keyboardSupport() method activates focusing with TAB key
            function keyboardSupport(sender, args) {
                var $fileInput = $(args._fileInputField);

                var $fakeInput = $fileInput.nextAll("input[class='ruFakeInput']");
                var $selectButton = $fileInput.nextAll("input[class='ruButton ruBrowse']");
                $fakeInput.attr("tabindex", "-1");
                $selectButton.attr("tabindex", "-1");

                $fileInput.focus(function (e) {
                    $selectButton.css("border", "1px dotted");
                });

                $fileInput.blur(function (e) {
                    $selectButton.css("border", "0px");
                });

                if (navigator.userAgent.indexOf("MSIE") != -1) {
                    $fileInput.keydown(function (e) {
                        if (e.keyCode == Sys.UI.Key.enter) {
                            e.preventDefault();
                            $fileInput.click();
                        }
                        if (e.keyCode == Sys.UI.Key.tab && e.shiftKey == false) {
                            $fakeInput.focus();
                        }
                        if (e.keyCode == Sys.UI.Key.tab && e.shiftKey == true) {
                            var $checkbox = $(".ruCheck", args.get_row());
                            if ($checkbox[0] != undefined) {
                                e.preventDefault();
                                $checkbox.focus();
                            }
                            else {
                                $fileInput.parent().focus();
                            }
                        }
                    });
                }

                if ($telerik.isOpera) {
                    var $checkbox = $(".ruCheck", args.get_row());
                    var $fileInputRow = $("input[type='file']", args.get_row());
                    var upload = $find("<%=RadUpload.ClientID %>");
                    var accesskey = upload._accessKey;

                    var $fileInputs = $("input[type='file']:first", $get("<%=RadUpload.ClientID%>"));

                    // attach accesskey to the first file input because it is not possible to determine with javascript when the accesskey is pressed
                    if ($fileInputs.length == 1) {
                        $fileInputs.attr("accesskey", accesskey);
                    }

                    // to focus file input into Opera need to Tab twice
                    // the following code simulates double Tabbing
                    if ($checkbox != undefined) {
                        $checkbox.keydown(function (e) {
                            if (e.keyCode == Sys.UI.Key.tab) {
                                e.preventDefault();
                                $fileInputRow.focus();
                            }
                        });

                    }
                }
            }

            // the following methods are listening for keyboard combination which is equal to accesskey combination and simulate it's behaviour - focus the element
            $(document).keydown(function (e) {
                var accesskey = $find("<%=RadUpload.ClientID%>")._accessKey;

                if ($telerik.isFirefox) {
                    if (e.altKey == true && e.shiftKey == true && e.which == accesskey.charCodeAt()) {
                        focusOnFirstInput();
                    }
                }

                if ($telerik.isChrome || $telerik.isSafari || $telerik.isIE) {
                    if (e.altKey == true && e.which == accesskey.charCodeAt()) {
                        focusOnFirstInput();
                    }
                }
            });

            function focusOnFirstInput() {
                var firstInput = $("input[type='file']", $get("<%=RadUpload.ClientID%>"))[0];
                if (firstInput != undefined) {
                    firstInput.focus();
                }
            }

        </script>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451