title: How to match the answer in vb.net and asp.net?
body: <p>I random the 3 question to display on asp.net page. I want to match the security question with correct answer in database. But after I enter the correct answer in textbox and click the "Next" button, the answer cannot match the current question displayed on screen. But if I click the "Next" button, the next question displayed is matched with answer I enter on textbox  in previous question. I think this is because the answer is match the question and answer after refresh the page. Please help. Here is my code. thanks</p>
  
  <p>vb.net code</p>
  
  <pre><code>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 &gt; 0 Then
          Msg3.Text = "Correct Answer"
      Else
          Msg3.Text = "Invalid Answer"
      End If
  End Sub
  </code></pre>