Apr 20, 2017, 9:29 AM
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:
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.