Excel Export works part time.

Posted on 2007-07-24
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.
Question by:triplebd69
    LVL 17

    Accepted Solution

    Can you explain what your button to export to excell does? The code behind?
    LVL 4

    Assisted Solution

    The  page_load should be fire. Don't you have a IsPostBack condition?

    Author Comment

    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;
    using (OdbcConnection con = new OdbcConnection(Configuration.oConn))
    string oCMD = Session["Select"].ToString();
    OdbcDataAdapter daCMD = new OdbcDataAdapter(oCMD, con);
    Session["myDataset"] = ds;

    dgAdHoc.DataSource = ds;

    And the export button..

    private void btExcelX_Click(object sender, System.EventArgs e)
    //export to excel
    Response.Buffer= true;
    Response.ContentType = "application/";
    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);

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    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.…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now