By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

C#.Net Excel exporting web form instead of data

P: n/a
Liz
Hi! I have a .Net webpage that displays data in some datagrids populated
based on user search criteria. There is a button, that when clicked, the
data is exported to excel. For one user, I am seeing that it works
correctly the first time he tries the report, but if he reruns the
result set or even picks a different report, the web page itself is
exported to excel and not the data. He has the same Excel version as
others (Excel 2003) who are not able to recreate the issue. No errors
are sent to the client.

Has anyone ever seen this? Here's the code:

private void btnExport_Click(object sender, System.EventArgs e)
{
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
System.Web.UI.HtmlTextWriter(oStringWriter);

oHtmlTextWriter.Write("Overall Total Number of Searches: "
+lblTotSearches.Text);
oHtmlTextWriter.Write("<br>");

dgOrg.RenderControl(oHtmlTextWriter);
oHtmlTextWriter.Write("<br>");
dgFuncArea.RenderControl(oHtmlTextWriter);
oHtmlTextWriter.Write("<br>");
dgBodyArea.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());
Response.End();
}

Thanks!!
Liz

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.