Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从控件下载响应文件不起作用_C#_Asp.net - Fatal编程技术网

C# 从控件下载响应文件不起作用

C# 从控件下载响应文件不起作用,c#,asp.net,C#,Asp.net,更新:我收到通知 Uncaught Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. 以下是代码的主要部分: 我的主文件头: <%@ Register Src="~/UserControls/HostsContro

更新:我收到通知

Uncaught Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
以下是代码的主要部分:

我的主文件头:

<%@ Register Src="~/UserControls/HostsControl.ascx" TagPrefix="hosts" TagName="HostsControl" %>
问题是文件没有下载。我认为这是因为我使用了控件的响应


请告诉我是否缺少任何信息

您确定点击处理程序被点击了吗?excel@Andrei的内容类型处理程序被命中,当然我调试了它。关于第二部分,事实上ExportToExel不是我发布的。正在下载的文件是来自我的计算机的测试文本文件。当我将响应代码放入页面加载时,它会起作用。文件路径未设置为excel,它指向我的计算机中的txt文件。对不起,我没提那件事。
<%@ Register Src="~/UserControls/DataGridView.ascx" TagPrefix="dtbl" TagName="DataGridView" %>
<asp:ImageButton ID="imgExportToExcel" ImageUrl="~/images/files/excel.png" ToolTip="Export to excel" AlternateText="Excel" OnClick="ExportToExcel" runat="server" />
...create exel logic
FileInfo file = new FileInfo(filePath);
if (file.Exists)
{
    Response.ClearContent();
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "text/plain";
    Response.TransmitFile(file.FullName);
    Response.End();
}