Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   ViewState problem! (http://www.velocityreviews.com/forums/t76594-viewstate-problem.html)

=?Utf-8?B?RXlhbCBaaW5kZXI=?= 04-23-2004 05:46 PM

ViewState problem!
 
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 04-23-2004 05:59 PM

Re: ViewState problem!
 
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" <ezinder@otxresearch.com> wrote in message
news:E0CC26A5-F2BA-4B2A-9A94-ADC8DBF0453B@microsoft.com...
> 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=?= 04-23-2004 06:21 PM

Re: ViewState problem!
 
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 04-23-2004 07:39 PM

Re: ViewState problem!
 
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" <ezinder@otxresearch.com> wrote in message
news:DB78DEDF-34D3-461D-84C0-0715C1DFF0E1@microsoft.com...
> 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.





All times are GMT. The time now is 10:17 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.