Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing controls dynamically causes viewstate error on postback

Status
Not open for further replies.

Billkamm

Programmer
Joined
Feb 9, 2006
Messages
74
Location
US
I have a search page where if the results are found it returns a datagrid with the results. If no resutls are found it returns a literal control that outputs text saying "no results found".

The problem is when I do a search and get a datagrid then do another search and get no results I get an error on the second search because it says the viewstate does not have the same structure.

How can I fix this? (Error information below)


Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
 
In your web.config

Code:
 <system.web>
    [b]<pages enableViewStateMac="false" />[/b]
    <customErrors mode=....
 
That solution does not fix my problem. I am getting the same error at the same point.
 
Is there some sort of way to cause my dynamically controls (datagrid) to not be added to the viewstate?
 
If you are doing your work on an event after Load possibly.

Other than that I'm too tired to work out what you're tyring to say - please post the code :)


Yet another unchecked rambling brought to you by:
Oddball
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top