?
Solved

report Viewer and Viewstate

Posted on 2011-03-03
2
Medium Priority
?
609 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
CmdoProg2 earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
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:
This video teaches users how to migrate an existing Wordpress website to a new domain.
Suggested Courses

752 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