locked
help with viewstate persisting array values during postback RRS feed

  • Question

  • User1557658912 posted

    hi,

    I am relatively new to the asp.net environment but have a need to save and re-use the state of a number of arrays in my page design

    I have read alot of the forums and MSDN articles, but am just stuck and now getting the error -

    Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The state information is invalid for this page and might be corrupted.

    I have tried to change the ViewStateMAC / EnableViewState values, currently they are -

    EnableViewStateMac="False"

    EnableViewState="True"

    if it's relevant I am on a Virtual Machine, which is why I tried to turn off the ViewStateMAC

    I'd really appreciate some assistance here and I am expecting this will be a simple thing somewhere

    here's the code snippets I have written from referencing the other articles thus far....

    I have dimensioned the array(s) as modular level so I can access them accross the whole of the page code, which is the validation aspect of why i wanted to use arrays

    Public Class Class name
    
        Inherits System.Web.UI.Page
    
        Dim marrDWNValues(9999, 4) As String
    
        ..... all the other code
    
    End Class


    here's the code to check the page load event to see if I want to re-use or need to load fresh from the database

       Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    
           ' these arrays do and include more than just a select list, so are used beyond the scope
           ' of just the SropDownlist if that makes sense
    
    
            If (Me.ViewState("marrSavedArraysFlagVIEWSTATE") = True) Then
    
                ' get the array values back from viewstate because we dont want to hit the database on every
                ' selectindex change
    
                marrDWNValues = CType(ViewState("marrDWNValuesVIEWSTATE"), Array)
    
    
            Else
                ' Arrays aren't in view state, so we need to load then
                GetDropDownListValuesintoArrays()
    
            End If
    
    
        End Sub
    

    here's how I have 'saved' the array values, expecting to be able to access them above

        Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
    
          ' there's a number of other arrays too, but for the purpose of this
    
            Me.ViewState.Add("marrSavedArraysFlagVIEWSTATE", True)
    
            Me.ViewState.Add("marrDWNValuesVIEWSTATE", marrDWNValues)
    
    
        End Sub

    Friday, May 10, 2013 10:47 PM

Answers

  • User1557658912 posted

    update -

    Whilst I have found a solution using Session["item"], however am still interested in anyone's comments as to how ViewState shoudl be implimented.

    I am not sure if Session["item"] approach is more / less efficient than the use of Viewstate

    I gave up on the viewstate approach - this was not answered or solved

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 11, 2013 5:16 PM