Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Excel Export works part time.

Posted on 2007-07-24
3
Medium Priority
?
187 Views
Last Modified: 2010-04-15
I have a webapp that lets the user select the table and columns to build a select statement, that gets passes to a second web form that fills a datagrid.

All this works fine.

On this form I also have a button to let the user export to excel, this only seems to part of the time.  It appears that on the times it fails the OnInit and page_load never fire.  But I don't see why it only happens part of the time.  Or is it an issue with the data in the grid?

Any help would be great.
0
Comment
Question by:triplebd69
3 Comments
 
LVL 17

Accepted Solution

by:
Daniel Reynolds earned 750 total points
ID: 19562048
Can you explain what your button to export to excell does? The code behind?
0
 
LVL 4

Assisted Solution

by:aponcealbuerne
aponcealbuerne earned 750 total points
ID: 19563257
Hi:
The  page_load should be fire. Don't you have a IsPostBack condition?
0
 

Author Comment

by:triplebd69
ID: 19564663
Here is the code in the page load...

private void Page_Load(object sender, System.EventArgs e)
{
da = (DataObject)Session["DataObject"];
string xSel = Session["Select"].ToString();
DataSet ds = new DataSet();
            
if (Page.IsPostBack)
{
if (Session["myDataset"] != null)
{
ds = (DataSet)Session["myDataset"];
dgAdHoc.DataSource = ds;
dgAdHoc.DataBind();
}
}
else
{
using (OdbcConnection con = new OdbcConnection(Configuration.oConn))
{
con.Open();
string oCMD = Session["Select"].ToString();
OdbcDataAdapter daCMD = new OdbcDataAdapter(oCMD, con);
con.Close();
daCMD.Fill(ds);                              
Session["myDataset"] = ds;

dgAdHoc.DataSource = ds;
dgAdHoc.DataBind();
}                        
}
}

And the export button..

private void btExcelX_Click(object sender, System.EventArgs e)
{
//export to excel
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.ClearControls(dgAdHoc);
dgAdHoc.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
//Response.End();
}
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question