我随机将 3 个问题显示在 asp.net 页面上。我想将安全问题与数据库中的正确答案相匹配。但是当我在文本框中输入正确答案并单击“下一步”按钮后,答案与屏幕上显示的当前问题不匹配。但是,如果我单击“下一步”按钮,显示的下一个问题与我在上一个问题的文本框中输入的答案相匹配。我认为这是因为刷新页面后答案与问题和答案相匹配。请帮忙。这是我的代码。谢谢
vb.net代码
Dim SecurityQuestion As New DBDataContext
Dim randomNumber As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim SecurityQuestion As New DBDataContext
Dim rowCount As Integer = (From t In SecurityQuestion.tblSecurityQuestions Select t).Count + 1
End Sub
Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
ValidateAnswer()
End Sub
Private Sub LoadSecurityQuestion()
Dim SecurityQuestion As New DBDataContext
Dim mySecurityQuestion = (From c In SecurityQuestion.tblSecurityQuestions Where c.PkID = randomNumber Select c)
Dim rowCount As Integer = (From t In SecurityQuestion.tblSecurityQuestions Select t).Count + 1
randomNumber = New Random().Next(1, rowCount)
With gvQuestion
.DataSource = mySecurityQuestion
.DataBind()
End With
End Sub
Private Sub ValidateAnswer()
Dim SecurityQuestion As New DBDataContext
Dim validate = (From r In SecurityQuestion.tblRegistrations From s In SecurityQuestion.tblSecurityQuestions _
Where s.PkID = r.Q01 And r.A01 = txtSecurityAns.Text And r.UserID = ad And s.PkID = randomNumber _
Select r)
If validate.Count > 0 Then
Msg3.Text = "Correct Answer"
Else
Msg3.Text = "Invalid Answer"
End If
End Sub