This are the main parts of the code:

My main file header:

<%@ Register Src="~/UserControls/HostsControl.ascx" TagPrefix="hosts" TagName="HostsControl" %>

The hostControl Uses:

<%@ Register Src="~/UserControls/DataGridView.ascx" TagPrefix="dtbl" TagName="DataGridView" %>

In the datagridView i have an event:

<asp:ImageButton ID="imgExportToExcel" ImageUrl="~/images/files/excel.png" ToolTip="Export to excel" AlternateText="Excel" OnClick="ExportToExcel" runat="server" />

Now on the ExportToExel I have:

...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();
}

The problem is the file isnt download. The ExportToExcel Works if i use it from the hostControl directly.

Why is it not working when used from dataGridView.

Please tell me if any information is missing

Related posts

Recent Viewed