viewstate error

liunx

Guest
I have alot of forms in my application so i have had to make a helper class since all the forms almost the same activity,, but
every one is just a little different..


i am reveiving an error now after creating the helper class


Can anyone give me any ideas of how to even track an error like this one down?
any help at all is great!

erik.

Error that i am receiving
===================================================

Server Error in '/SuperCenter' Application.
--------------------------------------------------------------------------------

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.

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)
System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
System.Web.UI.Control.LoadViewStateRecursive(Object savedState)
System.Web.UI.Page.LoadPageViewState()
System.Web.UI.Page.ProcessRequestMain()




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

===============================================================================

How i am accessing the helper class

one way
---
Dim CC As ControlCollection
For Each c In Me.Controls
CC.Add(c)
Next c
CC.Add(CType(Me.FindControl("panCompany"), Panel))
CC.Add(CType(Me.FindControl("panREenter"), Panel))
CC.Add(CType(Me.FindControl("PanCompanyDescription"), Panel))
oHelper.MakeReadyForSQl(CC)
'Check to see if any of the textboxes were empty and if so inform the user

2nd way
-----

Public Sub ClearAll()
'
Dim oHelper As New Helper
'
Dim CC As ControlCollection
Dim c As Control
Dim oP As Panel
Dim p2 As Panel
'For Each c In Me.Controls
' If TypeOf c Is Panel Then
' oP = CType(c, Panel)
' p2 = oP
' CC.Add(oP)
' End If
'Next c
oHelper.Loop_and_Reset(False, Nothing, Nothing, Me.Controls)

Me.lblError.Text = ""
'
End Sub

====================================================

One of the methods in the helper class
====
Public Sub Loop_and_Reset(ByVal WithInform As Boolean, Optional ByRef oPanel As Panel = Nothing, _
Optional ByRef oUserControl As UserControl = Nothing, _
Optional ByVal oControls As ControlCollection = Nothing)

'Set the arraylist to hold the controls
Dim pA As New ArrayList
Dim ucA As New ArrayList

'
If IsNothing(oPanel) Then
Else
oControls.Add(oPanel)
End If
If IsNothing(oUserControl) Then
Else
oControls.Add(oUserControl)
End If

If IsNothing(oControls) Then
'Do nothing
Else

For Each c In oControls
If TypeOf c Is Panel Then
p = CType(c, Panel)
pA.Add(p)
End If
If TypeOf c Is UserControl Then
uc = CType(c, UserControl)
ucA.Add(uc)
End If
If TypeOf c Is TextBox Then
txbx = CType(c, TextBox)
End If
If TypeOf c Is ListBox Then
Lb = CType(c, ListBox)
End If
If TypeOf c Is Label Then
lbl = CType(c, Label)
End If
Next c
'
End If

If WithInform = False Then
Else
If IsNothing(pA) Then

For i As Int32 = 0 To pA.Count - 1

Dim pH As Panel = CType(pA(i), Panel)
For EachMoved to .NETYou have to make sure you're building everything on each load. If your form has say 5 controls on it before postback, and 6 after, the viewstate won't match and you get that error. Build the form from the form load and that should take care of it. Or you can just turn off the viewstate.
 
Back
Top