Results 1 to 3 of 3

Thread: [2008] ViewState To Store List Of

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Location
    Bentonville, AR
    Posts
    22

    [2008] ViewState To Store List Of

    I'm working with ASP.net 3.5 and having a problem with adding an item to a List of a Structure in the ViewState.

    I've declared the item to be added as New, but it complains when trying to insert into the viewstate object.

    here's the code...

    Code:
            Public Property QuestionsCorrect() As QuestionAnswer
                Get
                    Return ViewState("QuestionsCorrect")
                End Get
                Set(ByVal value As QuestionAnswer)
                    ViewState("QuestionsCorrect") = value
                End Set
            End Property
    Code:
           Public Sub ProcessAnswers()
                Dim qA As New QABase
                Dim answerLetter As String = hidClickedAnswer.Value
                Select Case answerLetter
                    Case "A"
                        If ActiveQuestionAnswer = 0 Then
                            qA.Correct = True
                        Else
                            qA.Correct = False
                        End If
                    Case "B"
                        If ActiveQuestionAnswer = 1 Then
                            qA.Correct = True
                        Else
                            qA.Correct = False
                        End If
                    Case "C"
                        If ActiveQuestionAnswer = 2 Then
                            qA.Correct = True
                        Else
                            qA.Correct = False
                        End If
                    Case "D"
                        If ActiveQuestionAnswer = 3 Then
                            qA.Correct = True
                        Else
                            qA.Correct = False
                        End If
                    Case "E"
                        If ActiveQuestionAnswer = 4 Then
                            qA.Correct = True
                        Else
                            qA.Correct = False
                        End If
                End Select
                qA.QuestionId = ActiveQuestion
                QuestionsCorrect.QuestionList.Add(qA)
                If ActiveQuestion < 10 Then
                    ActiveQuestion = ActiveQuestion + 1
                End If
            End Sub
    Here's the class for all that
    Code:
    <Serializable()> _
    Public Class QuestionAnswer
        Private _QuestionList As New List(Of QABase)
        Public Property QuestionList() As List(Of QABase)
            Get
                Return _QuestionList
            End Get
            Set(ByVal value As List(Of QABase))
                _QuestionList = value
            End Set
        End Property
    End Class
    
    <Serializable()> _
        Public Class QABase
        Private _QuestionId As Integer
        Private _Correct As Boolean
    
        Public Property QuestionId()
            Get
                Return _QuestionId
            End Get
            Set(ByVal value)
                _QuestionId = value
            End Set
        End Property
        Public Property Correct()
            Get
                Return _Correct
            End Get
            Set(ByVal value)
                _Correct = value
            End Set
        End Property
    End Class
    i've been working on this for sometime and can't figure it out...any help is greatly appreciated

  2. #2
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: [2008] ViewState To Store List Of

    Is the Public Property QuestionsCorrect() that sets/gets the viewstate in a code file in the app_code folder? because viewstate is page specific and I don't think you can get access to it that way. I think you could pass a refrence of the page to the property and use it to gain access but Im not sure...

    Some more info on the actual error would help

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2008] ViewState To Store List Of

    Set Option Strict On and declare your public properties properly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width