Link to home
Start Free TrialLog in
Avatar of kay2kay
kay2kay

asked on

report Viewer and Viewstate

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.

ASKER CERTIFIED SOLUTION
Avatar of CmdoProg2
CmdoProg2
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kay2kay
kay2kay

ASKER

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”