Code Toad (grover_rover2k) wrote in aspdotnet,
Code Toad
grover_rover2k
aspdotnet

Curious bug, or problem with code?

I've got a curious error with ASP.NET 2.0 but before I go reporting it to Microsoft, I thought I'd toss it around here:

I've been playing around with the new GridView control and so far it's been quite nice with the new gimmicks -- cuts about 90% of my code straight out. However... Inserting isn't implemented yet. It is, however, implemented in the DetailsView control.

So I decided to tackle the problem this way:

MyForm
|
-------> MyMultiView
|
-------------> View1 => MyGridView, MyInsertButton
|
-------------> View2 => MyDetailsView

I have a form with a multiview. The multiview has two views, one with a Gridview and a button entitled 'Insert', the other with a DetailsView. For viewing/editing/deleting, I use the GridView. For insertion, I switch views to the DetailsView and change mode to insert. So far so good.

Next, when the DetailsView changes modes (back to readonly), I have it switch back to the original view. Here's where the error occurs: any other action throws the following exception...

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.

Source
Error:



An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.


Stack Trace:


[HttpException (0x80004005): 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.]
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +589
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +404
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +404
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +404
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +404
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +404
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +404
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +404
   System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +404
   System.Web.UI.Page.LoadAllState() +608
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1826



So -- where is the problem coming from? Am I getting the events screwed up? Is there something I'm forgetting? Or is there really something amiss..?

Just in case, here's the code:

Sub AddActivity_Click(ByVal sender As Object, ByVal e As System.EventArgs)
AdminMultiView.ActiveViewIndex = 4
DetailsView1.ChangeMode(DetailsViewMode.Insert)
End Sub

Sub DetailsView1_ModeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If Not DetailsView1.CurrentMode = DetailsViewMode.Insert Then
AdminMultiView.ActiveViewIndex = 0
End If
End Sub
Subscribe
  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 4 comments