0

Error Message

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 cont

The problem is Pageload function is not getting called, when Clicking for a Second time on GridView .GridView columns are linkButtons. It has multiple Columns with linkButtons. When clicking on gridview it will redirect to linkbutton functionality.

For first click its working fine, The problem is with the second click.

If pageload gets called, my problem is solved.
I tried by Googling, I am unable to find solution. Help me out.

BenMorel
  • 34,448
  • 50
  • 182
  • 322

3 Answers3

0

The error you mention occurs when you add controls dynamically. Seems you are adding some controls on the first PortBack.

Asp.net needs you to add the controls back on every PostBack after that. The best place to add these back is Init.

If the control tree in the ViewState doesn't match the one you sent on the previous response, you will get an error. As LoadViewState is called before Load unless you resolve this, Load will not fire.

Refer: Asp.net Page Lifecycle

nunespascal
  • 17,584
  • 2
  • 43
  • 46
0

If you want to a piece of code to execute every time page is reloaded, then do not write code as follows

if(!isPostBack)
{ //code }

Do not write in !IsPostBack

0

Try setting the PlaceHolder that is hosting your controls to EnableViewState="False" if you don't need it, otherwise check out Failed to load viewstate. The control tree into which viewstate is being loaded.

Community
  • 1
  • 1
Hassan Mokdad
  • 5,832
  • 18
  • 55
  • 90