ViewState object lost in Master Page Load
Asked Answered
H

2

5

I am assigning ViewState["something"] in Page Load of content page and when I try to access the ViewState variable in Master Page Load event handler, the viewstate variable is lost.Can anyone guide me why this is happening and the solution.

Haggle answered 18/12, 2008 at 16:21 Comment(0)
O
7

Master pages and content pages do not share the same ViewState. If you are trying to pass something from the content page to the master page there are a couple of alternatives:
- use this.Context.Items that is common to the entire site during an HTTP request
- make a public property on the master page, cast this.Master from the content page to the master page class and set the property
- use Session

Ostend answered 18/12, 2008 at 17:9 Comment(0)
A
0

Maybe (just found it on the web) this is a hint to the solution:

Unless the MasterPage has its ViewState turned on, all controls below it would lose their state.

Found this in a blog post titled MasterPage and viewstate issue. Could it have something to do with the Viewstate being turned off in the master page?

Alaster answered 18/12, 2008 at 16:26 Comment(1)
I am using a viewstate object declaratively in code. aslo checked that view state of my master page is turned on...Haggle

© 2022 - 2024 — McMap. All rights reserved.