How to download a file on RadContentMenuItem Click

3 posts, 0 answers
  1. K
    K avatar
    10 posts
    Member since:
    Jan 2013

    Posted 14 Jul Link to this post

    I want to call a function that writes a file for download from a RadContextMenu.  The function works fine when I call it from a button click. But I can't call it from the server side OnContextMenuItemClick because the Response.End() call doesn't let the menu click finish (the load icon just keeps going).  So I am trying to intercept the menu click on the client side, cancel the event, and post the button click instead.  My breakpoint on javascript _doPostBack() gets hit,  my breakpoint on Page_Load gets hit, but my breakpoint on ButtonRptRpt_Click function does not.  Why not?

    How can I download a file as a result of a RadMenuItem click? (Opening another browser tab is not an option.)

    <telerik:RadTreeView ID="TreeViewBatchRules" runat="server" CheckBoxes="True"
        MultipleSelect="True" ToolTip="Right-click on nodes to see rule batch run menu."
          <telerik:RadTreeNodeBinding Expanded="False" />
          <telerik:RadTreeViewContextMenu ID="TreeViewBatchRulesContextMenu" runat="server">
              <telerik:RadMenuItem Value="Thing1" Text="Thing 1">    
                 <telerik:RadMenuItem Value="CreateReport" Text="Create Report">
    <!-- works fine on button click --> 
    <asp:Button ID="ButtonRunRpt" runat="server" Text="Run Report" OnClick="ButtonRunRpt_Click" />

    function TreeViewBatchRules_ClientContextMenuItemClicking(sender, eventArgs) { 
        var node = eventArgs.get_node();
        var item = eventArgs.get_menuItem();
        var menu = item.get_menu();   
        if (item.get_text() == "Create Report"){
            var ruleId = node.get_value();
            // the postback gets called but doesn't "arrive" at the ButtonRunRpt_Click
            var btnId = "<%=ButtonRunRpt.ClientID %>"
            __doPostBack(btnId, '');
    protected void TreeViewBatchRules_ContextMenuItemClick
                      (object Sender,
                           Telerik.Web.UI.RadTreeViewContextMenuEventArgs e)
        int ruleId = int.Parse(TreeViewBatchRules.CheckedNodes[0].Value);
        switch (e.MenuItem.Value)
           case "Thing1" : ... break;
           case "CreateReport" : BuildReport(ruleId); break; // load icon won't go away; file doesn't download       
    protected void ButtonRunRpt_Click(object Sender,
                                      EventArgs e)
        int ruleId = int.Parse(TreeViewBatchRules.CheckedNodes[0].Value);
    private void BuildReport(int nodeId)
        var ms = GetReport(ruleId);
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.ContentType = "application/pdf";  
        HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename='myReport.pdf'");     
  2. K
    K avatar
    10 posts
    Member since:
    Jan 2013

    Posted 14 Jul in reply to K Link to this post

    I posted this as a support ticket once I realized that was the better option for me.  Sorry for the duplication.
  3. DevCraft R3 2016 release webinar banner
  4. Nencho
    Nencho avatar
    1446 posts

    Posted 15 Jul Link to this post


    I have already replied to your question in the support ticket, which is why, I would ask you to continue the correspondence in the other thread.

    Than you!

    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top