Solved

report Viewer and Viewstate

Posted on 2011-03-03
2
575 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
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 dynamically set the form action using jQuery.

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

9 Experts available now in Live!

Get 1:1 Help Now