ViewState problem!

G

Guest

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
 
K

Kevin Spencer

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 said:
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.
 
G

Guest

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.
 
K

Kevin Spencer

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 said:
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..
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top