Download File in Content Page

4 posts, 1 answers
  1. Technology
    Technology avatar
    53 posts
    Member since:
    Jul 2010

    Posted 08 Oct 2010 Link to this post

    Dear developers hello,

    I use RadExplorer, in my classic website, with the option to download (or open) files with double click. It works great.

    Now i changed my pages and i use Master and Content pages, instead of classic.
    RadExplorer is in the Content Page of a Master Page.
    After that change, the download is not working. I double click the file and it does nothing (download or open).
    The file Handler.ashx is the same.

    I use:
    Visual Studio 2008 v9.0.30729.1 SP (ASP.NET Visual Basic)

    RadControls for ASP.NET Ajax 2010.2.929.35 Trial

    Windows 7

    If you need any other information, please let me know.
    Thank you in advance for your time.

    Best Regards
    Navarino Technology Department

    Below you will find the code of my content page.

    <%@ Page Title="" Language="VB" MasterPageFile="~/mpMainMenu.master" AutoEventWireup="true" CodeFile="cInvoices.aspx.vb" Inherits="cInvoices" %>
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
            <span class="style1">
            <asp:Label ID="lblUserName"
            <span class="style1">.
            <br />
            You can download or open the selected file (according the selection below), with
            double click.
            <br />
            <asp:RadioButton ID="rbDownload"
                             Text="Download (Save the file to your computer)" />
            <asp:RadioButton ID="rbOpen"
                             Text="Open (Open the file in Viewer)" />
            <telerik:RadFileExplorer ID="RadFileExplorer1"
                                     VisibleControls="TreeView, Grid, ContextMenus"
                                     style="text-align: left"
                                     Width="725px" >
                                     <Configuration SearchPatterns="*.*"></Configuration>
        <script type="text/javascript">
                function OnClientFileOpen(oExplorer, args) {
                    var item = args.get_item();
                    var fileExtension = item.get_extension();
                    var fileDownloadMode = document.getElementById("rbDownload").checked;
                    if ((fileDownloadMode == true) && (fileExtension == "jpg" || fileExtension == "pdf")) {// Download the file
                        // File is a image document, do not open a new window
                        // Tell browser to open file directly
                        var requestImage = "Handler.ashx?path=" + item.get_url();
                        document.location = requestImage;
                    setTimeout(function() {
                        var oWindowManager = oExplorer.get_windowManager();
                        var previewWinow = oWindowManager.getActiveWindow(); // Gets the current active widow
                        previewWinow.setSize(500, 500); // Set the new size of the window
                    }, 100); // Some timeout is required in order to allow the window to become active
  2. Answer
    Fiko avatar
    1406 posts

    Posted 14 Oct 2010 Link to this post


    The problem comes from this code:
    var fileDownloadMode = document.getElementById("rbDownload").checked;

    When a master page is used (or any Naming container), then the IDs of the server controls are changed and. In your case you have 3 options;
    1. Use an HTML element (without runat="server" attribute) instead of the rbDownload server control
    2. If you are developing the application using .NET40, you can set ClientIDMode="Static" property of the rbDownload server control
    3. You can use this approach in order to get the reference to the rbDownload server control:
      var fileDownloadMode = $get("<%= rbDownload .ClientID %>").checked;
      Please note that in some cases the server parentheses (<%= %>) cause an error on the page, so I recommend you to wrap the JavaScript code in <telerik:RadScriptBlock> control.

    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
  3. Technology
    Technology avatar
    53 posts
    Member since:
    Jul 2010

    Posted 14 Oct 2010 Link to this post

    Dear Fiko,

    I used the option 3 and it's working great now.

    Thank you for your help.

    Best regards,
    Navarino Technology Dept.
  4. Daniel
    Daniel avatar
    5 posts
    Member since:
    Nov 2010

    Posted 17 Feb 2011 Link to this post


    i have the same problem. But my Code is server side. 
    I am using a radgrid to show some Items with ID, filename and description. 
    If one of the items is clicked i use the ID to get the base64 string of the file from a database.
    I convert the base64 string to bytes.
    Then i provide my download function with the bytevalue and the filename. This works fine.
    But at some point my download function doesn´t open the download dialog.
    The download function is the contentpage. 
    This is the download function:

    Function download_file(ByVal dateibytes() As Byte, ByVal FileName As String) As Integer
                If dateibytes.Count = 0 Then
                    Return (0)
                End If
                Response.AppendHeader("content-disposition", "attachment; filename=" & FileName.ToString)
                Response.AppendHeader("content-length", dateibytes.Length.ToString())
            Catch ex As Exception
            End Try

            Return (0)
        End Function

Back to Top