[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
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
Re: [2008] ViewState To Store List Of
Set Option Strict On and declare your public properties properly.