Question

I have a group of controls on the Master Page. I use as a collection of links(HyperLink controls) to all the pages. When I navigate thru the pages I was setting the specific link to hl.Visible = False for the page currently open. I have noticed that this messes up the ViewState. I hate having a link to a page that is already present, is there a way to do this without messing up the ViewState? There are no dynamic controls on the page.

What techniques would you use for this?

No correct solution

OTHER TIPS

More generally this error happens when the control hierarchy of the page changes in a way that prevents the framework to load the view state. The view state mechanism assumes that the control hierarchy is the same on load as it was when it was saved.

This might look as a random error because there are cases when changing the controls in the page does not prevent the view state from loading. Have a look in your page and look for controls that are dynamically created/deleted. Ensure that any controls are added to the page before the view state is loaded (that would be before page Load event).

Unfortunately there is no way to see which exactly is the guilty control that is not added correctly to the control hierarchy. A common way to see this error is to add some dynamic controls on an event (for example on a drop down selected index changed) - this way their state is saved to view state - but not add them again on postback - this way the view state is invalid because the controls do not exists any more when the view state is loaded.

Source

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top