473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

Nov 18 '05 #1
3 1736
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" <ez*****@otxresearch.com> wrote in message
news:E0**********************************@microsof t.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.

Nov 18 '05 #2
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.
Nov 18 '05 #3
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" <ez*****@otxresearch.com> wrote in message
news:DB**********************************@microsof t.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.

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
3
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
2
by: Ben Rush | last post by:
Hello World, Okay, I have spent the day browsing the newsgroups and reading up on article after article concerning ViewState corruption and so forth, and I have a couple questions. We...
10
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and...
2
by: Janaka | last post by:
We have managed to lock down 99% of the application errors occurring in our asp.net sites. The only errors which occur on a regular basis now are viewstate errors. We have disabled viewstate on...
6
by: John | last post by:
Hi all, I am using dynamic user controls within my web app and these controls are loaded into placeholders via the LoadControl method. My problem is this: I have usercontrolA loaded into a...
2
by: epigram | last post by:
I'm responding to a button click event on an asp.net web form. I then need to retrieve the value from a TextBox control and I want to compare it against the control's previous value to see if it...
6
by: hlubocky | last post by:
I thought I had a good grasp of the problem related to dynamically creating controls, but it appears that as my application grew in complexity, the problem has resurfaced. As I understand it, in...
1
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
0
by: Scott Roberts | last post by:
I always thought that the viewstate "keys" included the control ID. As long as the control IDs were unique, there shouldn't be any conflicts. Well, it appears that that may not be the case with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.