What is wrong... my intention is the excel file must download to the client on click of a button.
Here when i click on the save and open the file from the local drive the xls is perfect.
but when i click on open .... it downloads a copy of the aspx page where it says the format is different or the file is corrupted.
This is my code
I found if i remove the multiview and the view the same exact code works perfectly. I have another form where this kind of set up works(multiview-view-updatepanel). I dont understand the difference.
What is wrong?
Page has a buttion inside Multiview->view->updatepanel
<asp:MultiView ID="mvwReports" runat="server">
<asp:View ID="vwTotalCostOfOwnership" runat="server">
<div id="divExport" runat="server" class="aright">
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<asp:ImageButton ID="imgBtnExcel" runat="server" CausesValidation="false" ToolTip="Excel"
Visible="true" AlternateText="Excel" Enabled="true" ImageUrl="~/App_Themes/WebBlue/images/excel_icon.gif"
OnClick="imgBtnExcel_OnClick" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="imgBtnExcel" />
</Triggers>
</asp:UpdatePanel></div>
</asp:View>
</asp:MultiView>
Code behind
protected void Page_Load(object sender, EventArgs e)
{
mvwReports.ActiveViewIndex = 0;
}
protected void imgBtnExcel_OnClick(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);//(HttpCacheability.Private);
Response.Expires = -1;
Response.Buffer = true;
Response.AddHeader("Content-Disposition", string.Format("{0};FileName=\"{1}\"",
"attachment","test" + ".xls"));
Response.TransmitFile("e:\\temp\\excel\\test.xls");
HttpContext.Current.ApplicationInstance.CompleteRequest();
}