ViewState problem!

Discussion in 'ASP .Net' started by =?Utf-8?B?RXlhbCBaaW5kZXI=?=, Apr 23, 2004.

  1. Hello All,

    Here is a little problem I ran into. I'd like to see if anyone can help me solve it

    I have an HTML table that I assign to a label control. I set my Response.ContentType = "application/vnd.ms-excel", so that I can present this html table as an Excel Document. If the amount of data (number of rows) in the table is relatively low, the Excel Document is processed with no problems. When a larger set of data is assigned, however, the Excel Document cannot detect the HTML Table to process. I assume this is due to the ViewState input string. I believe that Excel will only go through so many lines before it determines what can be processed in tabular form.

    The plot thickens..

    When I disable ViewState, I get garbage printed on an Excel sheet.. The Excel sheet freezes for a good 3 minuets or so, and prints gibberish.

    Here is my code:
    -----------------------------------------------------------------------------------------------------------------------------------------
    private void Page_Load(object sender, System.EventArgs e

    Response.ContentType = "application/vnd.ms-excel";
    if(Session["exceldata"] != null)
    {
    lblExcel.EnableViewState = false
    lblExcel.Text = (Session["exceldata"].ToString())


    -----------------------------------------------------------------------------------------------------------------------------------------

    Any thoughts? Ideas? Advice?
    I'd appreciate it if you have one for me!

    Thank you in advance.
    -Eyal Zinder
    =?Utf-8?B?RXlhbCBaaW5kZXI=?=, Apr 23, 2004
    #1
    1. Advertising

  2. Hi Eyal,

    Part of your problem stems from the fact that you are using your
    Response.ContentType all wrong. If you are putting something in a Label
    Control, you are creating an HTML document, NOT an Excel Spreadsheet. If you
    want to return an Excel Spreadsheet to the client, you must send ONLY an
    Excel Spreadsheet to the client. The Response.ContentType indicates the MIME
    type of the ENTIRE document, not a part of it.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Eyal Zinder" <> wrote in message
    news:...
    > Hello All,
    >
    > Here is a little problem I ran into. I'd like to see if anyone can help

    me solve it.
    >
    > I have an HTML table that I assign to a label control. I set my

    Response.ContentType = "application/vnd.ms-excel", so that I can present
    this html table as an Excel Document. If the amount of data (number of
    rows) in the table is relatively low, the Excel Document is processed with
    no problems. When a larger set of data is assigned, however, the Excel
    Document cannot detect the HTML Table to process. I assume this is due to
    the ViewState input string. I believe that Excel will only go through so
    many lines before it determines what can be processed in tabular form.
    >
    > The plot thickens..
    >
    > When I disable ViewState, I get garbage printed on an Excel sheet.. The

    Excel sheet freezes for a good 3 minuets or so, and prints gibberish.
    >
    > Here is my code:
    > --------------------------------------------------------------------------

    ----------------------------------------------------------------
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > Response.ContentType = "application/vnd.ms-excel";
    > if(Session["exceldata"] != null)
    > {
    > lblExcel.EnableViewState = false;
    > lblExcel.Text = (Session["exceldata"].ToString());
    > }
    > }
    > --------------------------------------------------------------------------

    ----------------------------------------------------------------
    >
    > Any thoughts? Ideas? Advice?
    > I'd appreciate it if you have one for me!
    >
    >
    > Thank you in advance.
    > -Eyal Zinder.
    >
    Kevin Spencer, Apr 23, 2004
    #2
    1. Advertising

  3. Thank you Kevin.

    Not sure exacly what you mean by that though..
    My intentions are not to have them download an Excel form or to create an Excel Document to be stored on the file server. My intentions are to take an existing reporting of data and alow the browser to display it in Excel.

    I would like to reuse my XSLT Templates, which now produce HTML Tables, and alow the client to view and save the file as an Excel sheet - right from the browser. I saw many exaples of 'Response.ContentType' as the method to achive this..

    Is there another way to achive this?

    Thank you again for all your help!
    -Eyal Zinder.
    =?Utf-8?B?RXlhbCBaaW5kZXI=?=, Apr 23, 2004
    #3
  4. Hi Eyal,

    When you embed an Excel Spreadsheet in an HTML document, it is much the same
    as embedding an image in an HTML document, in that the HTML document doesn't
    actually CONTAIN the object, but includes a reference to it. The browser
    then downloads the object separately and displays it in the document, as if
    it were part of the document. So, in essence, what you've seen is 2 separate
    "documents" - one is the HTML "host" and the other is the Spreadsheet. The
    Response.ContentType of the Spreadsheet is "application/vnd.ms-excel", butr
    the ContentType of the HTML document is not.

    I have never worked with an Excel Spreadsheet in an HTML page, but it sounds
    like you know where to find one. If you can, you should be able to find the
    code in the HTML document source code that embeds the Spreadsheet. Keep in
    mind that you're talking about 2 separate requests: one for the HTML
    document, and one for the .xls file.

    If you don't need to create the Excel document "on the fly" you can simply
    use the embedding syntax to have the browser download the Spreadsheet and
    include it in the page. You would not need any extra code to generate the
    Spreadsheet, only the HTML code in the host page that embeds it in the
    document. The browser will request the Spreadsheet by itself.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Eyal Zinder" <> wrote in message
    news:D...
    > Thank you Kevin.
    >
    > Not sure exacly what you mean by that though..
    > My intentions are not to have them download an Excel form or to create an

    Excel Document to be stored on the file server. My intentions are to take
    an existing reporting of data and alow the browser to display it in Excel.
    >
    > I would like to reuse my XSLT Templates, which now produce HTML Tables,

    and alow the client to view and save the file as an Excel sheet - right from
    the browser. I saw many exaples of 'Response.ContentType' as the method to
    achive this..
    >
    > Is there another way to achive this?
    >
    >
    > Thank you again for all your help!
    > -Eyal Zinder.
    Kevin Spencer, Apr 23, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Rush
    Replies:
    2
    Views:
    493
    Ben Rush
    Dec 5, 2003
  2. Steph
    Replies:
    2
    Views:
    1,637
    heislord5
    May 11, 2011
  3. ujjc001
    Replies:
    0
    Views:
    1,355
    ujjc001
    Jul 27, 2005
  4. sck10
    Replies:
    6
    Views:
    883
    sck10
    Sep 1, 2006
  5. mark

    Viewstate errors... how do I get viewstate working?

    mark, Feb 20, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    261
Loading...

Share This Page