Solved

report Viewer and Viewstate

Posted on 2011-03-03
7
1,364 Views
Last Modified: 2013-11-28
I am using the report viewer on my web application. I do not want to turn the viewstate on for the entire application. So the viewstate on the webconfig is turned off

However the viewstate of the page the control is on , the viewstate of the control, the viewstate of the master page have all been turned on.
the control is within a form runat=server

Still, the report viewer errs out with the message asp.net viewstate needs to be enabled.


0
Comment
Question by:kay2kay
  • 4
  • 3
7 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35028020
...and if you turn on the viewstate on for the entire application, ...does it work...?
0
 

Author Comment

by:kay2kay
ID: 35028894
yes it does.. which we do not want to do.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35030467
<which we do not want to do. >

Just curious, ...Why not?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:kay2kay
ID: 35030500
We have our own post-back system in place and we don't want to carry the payload of the view state.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35031108
OK, then wait for a few other Experts to chime in.

My thought is that perhaps you could turn viewstate on for the entire application, *temporarilly" (Just to get this up and running), until a less burdensome configuration is found.

JeffCoachman
0
 

Accepted Solution

by:
kay2kay earned 0 total points
ID: 35190302
Solution:


On our site we turn off the viewstate by default in the webconfig . The thought is, if the view state is turned on at the Page level, all the controls under it would be able to use the viewstate. This is what the general thoughts were in all the blogs I read and on this forum

So the key is that the masterpage viewstate needs to be turned on.  Which I tried, by setting the masterpage.viewstate as true in the OnInit of the page life cycle.
This didn’t work either.

Came across a bunch of articles (some of which I am referring here for reading) http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx
“In general, this structure has no effect on how you construct your pages or program them. However, in some cases, if you set a page-wide property on the master page, it can affect the behavior of the content page, because the master page is the closest parent for the controls on the page. For example, if you set the EnableViewState<http://msdn.microsoft.com/en-us/library/system.web.ui.page.enableviewstate.aspx> property on the content page to true but set the same property to false in the master page, view state will effectively be disabled because the setting on the master page will take priority.”



http://odetocode.com/Blogs/scott/archive/2006/10/12/masterpage-issue-with-viewstate-disabled-in-web-config.aspx

http://forums.asp.net/t/1028912.aspx/1?EnableViewState+override+not+working+for+page+when+setting+defined+in+web+config

http://stackoverflow.com/questions/1015742/why-isnt-my-page-enableviewstate-overiding-the-pages-enableviewsate-in-the-web

and of course the kicker
http://geekswithblogs.net/vivek/archive/2006/10/04/93094.aspx

“The main points to consider are:

1.We can turn on/off the view state only if the Parent control has the same turned on. If view state is disabled in the parent control, then there would be no effect even if we turn on property for individual controls.

2. The MasterPage takes its value from the Web.config file and will reflect the same only if the ContentPage has view state turned on. If not, then "there is nothing to turn off".

3. A MasterPage is slightly different from other controls, it is in charge of things until Page_PreInit() is over. Only after the PreInit() event, it behaves like a true child control of the Page.

MasterPages can be a bit tricky unless we undertsand the complete Page lifecycle and the sequence of events. In short, it is helpful to remember that a MasterPage behaves like a control inside the Conent Page and all events, except the Init(), fire first for the outer control and then for the inner ones. For e..g:, Page_Load() of a Conent Page will fire first and then of the MasterPage, similarly OnInit() of the MasterPage will fire before that of the ContentPage”
0
 

Author Closing Comment

by:kay2kay
ID: 35225312
Understanding the life cycle  model and the way master pages are used, helped me fix the issue I had.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Read about why website design really matters in today's demanding market.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

746 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

12 Experts available now in Live!

Get 1:1 Help Now