Solved

report Viewer and Viewstate

Posted on 2011-03-03
2
595 Views
Last Modified: 2012-05-11
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
2 Comments
 
LVL 12

Accepted Solution

by:
CmdoProg2 earned 500 total points
ID: 35039036
Viewstate permission on the webconfig must turned on for the report viewer.  Viewstate works somewhat like authorization, once specifically denied, then subsequent values are ignored.  I usually toggle the viewstate at the page and control levels...

Try using two master pages, one for the rest of the site that has viewstate turned off and one for the report viewer.
0
 

Author Comment

by:kay2kay
ID: 35190329
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

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

792 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