Failed to load viewstate - Content Place holder

5.3k views Asked by At

My master page has a content place holder, and my page has 2 rad grids, within separate asp:panels. On a dropdown selection, respective grid is loaded into the page.

  1. I select grid 1 from dropdown
  2. Click on add new row, but dont cancel or add any new row(let that new row remain open)
  3. Select grid2 from dropdown, let the grid load
  4. Again select grid1 from dropdown

At this point, the grid1 opens, but i get following javascript error.

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: 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.

Any idea about the issue. I read in some forums that the issue might be, using same type of control in a single content place holder. Any suggestion on solution ???

3

There are 3 answers

0
RMN On BEST ANSWER

I cleared controls of both grids on dropdown selection change, before rebinding them. It solved my problem.

radgrid1.Controls.Clear(); radgrid2.Controls.Clear();

1
Beejee On

Without having more information it seems that your controls aren't on the page anymore after a postback. Are you deleting the rad grid's or are you just making them visible when needed? It can also be that you add them dynamically. This can cause problems with radgrids i think.

I think the best solution is to use One grid an manipulate it when the user has made a new selection. If the grids are very different from each other I would add multiple and make them visible when selected from the list(don't do this when you have more than 3 options).

3
nunespascal On

Same type of control in the same content place holder is not an issue.

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.

This occurs most often when you are dynamically adding and removing controls. Just changing the visibility should not give you an error.

Maybe showing some part of your code would help.