GridPanel - CommandColumn - download file like Button

  1. #1

    GridPanel - CommandColumn - download file like Button

    Hi,

    I have some problems in downloading a file using a CommandColumn included in a GridPanel.
    When I try to download a file using the CommandColumn the error message "BADRESPONSE: missing ) in parenthetical" appears.
    When I try to download a file using the Button it works perfectly.
    I know I missing something but I don't know what.

    I need to start the download of the file from the server side, clicking the disk icon at the specific row inside the GridPanel.

    Thanks


    Sample code:

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    
    <script runat="server">
    
        public class MyRecord
        {
            public int ID { get; set; }
            public String Field { get; set; }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                List<MyRecord> l_MyRecordList = new List<MyRecord>();
                l_MyRecordList.Add(new MyRecord { ID = 0, Field = "Value 0" });
                l_MyRecordList.Add(new MyRecord { ID = 1, Field = "Value 1" });
                l_MyRecordList.Add(new MyRecord { ID = 2, Field = "Value 2" });
                l_MyRecordList.Add(new MyRecord { ID = 3, Field = "Value 3" });
                l_MyRecordList.Add(new MyRecord { ID = 4, Field = "Value 4" });
                l_MyRecordList.Add(new MyRecord { ID = 5, Field = "Value 5" });
                l_MyRecordList.Add(new MyRecord { ID = 6, Field = "Value 6" });
                l_MyRecordList.Add(new MyRecord { ID = 7, Field = "Value 7" });
                l_MyRecordList.Add(new MyRecord { ID = 8, Field = "Value 8" });
                l_MyRecordList.Add(new MyRecord { ID = 9, Field = "Value 9" });
    
                m_Store.DataSource = l_MyRecordList;
                m_Store.DataBind();
            }
        }
    
        protected void m_Button_Click(object sender, DirectEventArgs e)
        {
            // This works, but I wrote this only for comparison of the two methods
            Download(null);
        }
    
        [DirectMethod(Namespace = "MyClass")]
        public void m_CommandColumn_Command(String p_Command, String p_ID)
        {
            // This doesn't works
            if (p_Command == "Download") { Download(p_ID); }
        }
    
        private void Download(String p_ID)
        {
            String l_SomeText = "Hello World!";
    
            byte[] l_BytesToWrite = Encoding.UTF8.GetBytes(l_SomeText);
    
            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            Response.ContentType = "text/txt";
            Response.AddHeader("Content-Disposition", "attachment;filename=\"Attachment.txt\"");
            Response.AddHeader("Content-Length", l_BytesToWrite.Count().ToString());
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.BinaryWrite(l_BytesToWrite);
            Response.Flush();
            Response.Close();
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head runat="server">
        <title></title>
    </head>
    
    <body>
    
        <form id="m_Form" runat="server">
    
        <ext:ResourceManager ID="m_ResourceManager" runat="server" />
    
            <ext:Button ID="m_Button" runat="server" Text="Download" Icon="Disk" Width="100" StandOut="true">
                <DirectEvents>
                    <Click OnEvent="m_Button_Click" IsUpload="true" />
                </DirectEvents>
            </ext:Button>
    
            <ext:GridPanel ID="m_GridPanel" runat="server" Title="GridPanel" Width="200">
                <Store>
                    <ext:Store ID="m_Store" runat="server">
                        <Model>
                            <ext:Model ID="m_Model" runat="server" IDProperty="ID">
                                <Fields>
                                    <ext:ModelField Name="ID" />
                                    <ext:ModelField Name="Field" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
    
                <ColumnModel>
                    <Columns>
                        <ext:CommandColumn ID="m_CommandColumn" runat="server" Width="25">
                            <Commands>
                                <ext:GridCommand CommandName="Download" Icon="Disk" StandOut="true" ToolTip-Text="Download" />
                            </Commands>
                            <Listeners>
                                <Command Handler="MyClass.m_CommandColumn_Command(command, record.data.ID);" />
                            </Listeners>
                        </ext:CommandColumn>
    
                        <ext:Column ID="m_ColumnID" runat="server" DataIndex="ID" Text="ID" Width="50" Align="Center" />
                        <ext:Column ID="m_ColumnField" runat="server" DataIndex="Field" Text="Field" Width="150" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>    
    
        </form>
    </body>
    
    </html>
    Last edited by thece; Apr 20, 2017 at 6:09 PM.
  2. #2
    Someone tells me: this is the right solution?

    <Listeners>
        <Command Handler="MyClass.m_CommandColumn_Command(command, record.data.ID, {isUpload:true});" />
    </Listeners>
    There's a better way?

    Thanks



    (Purged) Sample code:

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    
    <script runat="server">
    
        public class MyRecord
        {
            public int ID { get; set; }
            public String Field { get; set; }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                List<MyRecord> l_MyRecordList = new List<MyRecord>();
                l_MyRecordList.Add(new MyRecord { ID = 0, Field = "Value 0" });
                l_MyRecordList.Add(new MyRecord { ID = 1, Field = "Value 1" });
                l_MyRecordList.Add(new MyRecord { ID = 2, Field = "Value 2" });
                l_MyRecordList.Add(new MyRecord { ID = 3, Field = "Value 3" });
                l_MyRecordList.Add(new MyRecord { ID = 4, Field = "Value 4" });
                l_MyRecordList.Add(new MyRecord { ID = 5, Field = "Value 5" });
                l_MyRecordList.Add(new MyRecord { ID = 6, Field = "Value 6" });
                l_MyRecordList.Add(new MyRecord { ID = 7, Field = "Value 7" });
                l_MyRecordList.Add(new MyRecord { ID = 8, Field = "Value 8" });
                l_MyRecordList.Add(new MyRecord { ID = 9, Field = "Value 9" });
    
                m_Store.DataSource = l_MyRecordList;
                m_Store.DataBind();
            }
        }
    
        [DirectMethod(Namespace = "MyClass")]
        public void m_CommandColumn_Command(String p_Command, String p_ID)
        {
            if (p_Command == "Download") { Download(p_ID); }
        }
    
        private void Download(String p_ID)
        {
            String l_SomeText = "Hello World!";
    
            byte[] l_BytesToWrite = Encoding.UTF8.GetBytes(l_SomeText);
    
            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            Response.ContentType = "text/txt";
            Response.AddHeader("Content-Disposition", "attachment;filename=\"Attachment.txt\"");
            Response.AddHeader("Content-Length", l_BytesToWrite.Count().ToString());
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.BinaryWrite(l_BytesToWrite);
            Response.Flush();
            Response.Close();
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head runat="server">
        <title></title>
    </head>
    
    <body>
    
        <form id="m_Form" runat="server">
    
        <ext:ResourceManager ID="m_ResourceManager" runat="server" />
    
            <ext:GridPanel ID="m_GridPanel" runat="server" Title="GridPanel" Width="200">
                <Store>
                    <ext:Store ID="m_Store" runat="server">
                        <Model>
                            <ext:Model ID="m_Model" runat="server" IDProperty="ID">
                                <Fields>
                                    <ext:ModelField Name="ID" />
                                    <ext:ModelField Name="Field" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
    
                <ColumnModel>
                    <Columns>
                        <ext:CommandColumn ID="m_CommandColumn" runat="server" Width="25">
                            <Commands>
                                <ext:GridCommand CommandName="Download" Icon="Disk" StandOut="true" ToolTip-Text="Download" />
                            </Commands>
                            <Listeners>
                                <Command Handler="MyClass.m_CommandColumn_Command(command, record.data.ID, {isUpload:true});" />
                            </Listeners>
                        </ext:CommandColumn>
    
                        <ext:Column ID="m_ColumnID" runat="server" DataIndex="ID" Text="ID" Width="50" Align="Center" />
                        <ext:Column ID="m_ColumnField" runat="server" DataIndex="Field" Text="Field" Width="150" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>    
    
        </form>
    </body>
    
    </html>

Similar Threads

  1. Replies: 4
    Last Post: Oct 25, 2014, 1:12 AM
  2. Unable to Download Ext.net.example.dll file
    By Binai in forum 2.x Help
    Replies: 4
    Last Post: Jul 23, 2014, 2:22 PM
  3. download file with DirectEvent on GridPanel
    By novacp in forum 2.x Help
    Replies: 1
    Last Post: Feb 13, 2014, 10:38 AM
  4. 2.1 zip file download
    By gdog_5021 in forum 2.x Help
    Replies: 4
    Last Post: Dec 03, 2012, 11:14 AM
  5. File download
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Dec 05, 2008, 7:22 AM

Posting Permissions