无回传无法访问受保护的子(vb.net)

时间:2015-03-26 00:46:22

标签: javascript jquery asp.net vb.net

过去几个月,我一直在通过VB.Net开发一个Exam Generator网站。现在我正在执行(Take Exam)页面,用户将参加他自己的考试,然后他将被重定向到另一个页面以获得结果。

动态创建考试页面(用户选择的选项的单选按钮,标签和下拉菜单),并从SQL Server数据库中检索问题和答案的值。

此外,只要用户尝试访问或刷新此页面,问题和答案就会被洗牌。我通过SQL命令(ORDER BY NEWID())实现了shuffle。

我的问题是,我需要在点击提交按钮后处理用户的答案,但这非常困难,因为无论何时用户点击提交,页面都会针对每个问题和答案回复不同的值。我尝试使用AJAX,但它无法提供帮助,因为必须保护sub才能通过Page.FindControl()方法访问页面元素。

更新:我添加了部分代码以获得更多解释。

If (Request.Cookies("user") Is Nothing) Then
        Response.Redirect("~/index.aspx", False)
    ElseIf Request.UrlReferrer = Nothing Then
        Session.Abandon()
        Response.Redirect("~/main.aspx", False)
    Else
        .
        .
        .
        .
        sql = "SELECT * FROM examTime.dbo.questionexam WHERE examID = @eID ORDER BY type, NEWID()"
        cmd.CommandText = sql
        da.SelectCommand = cmd
        Try
            da.Fill(dtall)
            Variables.Variables.dtAll = dtall.Clone()
            For i As Integer = 0 To dtall.Rows.Count - 1 Step 1
                Variables.Variables.dtAll.ImportRow(dtall.Rows(i))
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        If mcqCount > 0 Then
            Dim dtmcq As New DataTable
            dtmcq.Columns.AddRange(New DataColumn(3) {New DataColumn("id", GetType(Integer)), New DataColumn("examID", GetType(Integer)), New DataColumn("questionID", GetType(Integer)), New DataColumn("type", GetType(Integer))})
            Dim mcqID As Integer
            Dim dtmcqQC As New DataTable
            Dim dtmcqAns As New DataTable
            Try
                panelQContainer.Controls.Add(New LiteralControl("<div class='text blue uppercase'>Multiple Choice Questions</div><div class='text grey uppercase small'>"" Choose the correct answer. ""</div>"))
                panelQContainer.Controls.Add(New LiteralControl("<div class='review-container-content'>"))
                For n As Integer = 1 To mcqCount Step 1
                    dtmcq.ImportRow(dtall.Rows(0))
                    dtall.Rows.RemoveAt(0)
                    dtall.AcceptChanges()
                    mcqID = Integer.Parse(dtmcq.Rows(n - 1).Item(2))
                    sql = "SELECT question, correct FROM examTime.dbo.question WHERE id = @qid"
                    qidP.Value = Integer.Parse(mcqID)
                    cmd.CommandText = sql
                    da.SelectCommand = cmd
                    da.Fill(dtmcqQC)
                    panelQContainer.Controls.Add(New LiteralControl("<div class='text red uppercase underline'>Question #" & n & ":</div>"))
                    panelQContainer.Controls.Add(New LiteralControl("<div class='text black'>" & dtmcqQC.Rows(0).Item(0) & "</div>"))
                    panelQContainer.Controls.Add(New LiteralControl("<table class='t-max'>"))
                    panelQContainer.Controls.Add(New LiteralControl("<tr><td class='text grey uppercase'><input type='radio' name='mcq" & n & "' value='A' />&nbsp;Answer A.</td>"))
                    panelQContainer.Controls.Add(New LiteralControl("<td class='text grey uppercase'><input type='radio' name='mcq" & n & "' value='B' />&nbsp;Answer B.</td>"))
                    panelQContainer.Controls.Add(New LiteralControl("<td class='text grey uppercase'><input type='radio' name='mcq" & n & "' value='C' />&nbsp;Answer C.</td>"))
                    panelQContainer.Controls.Add(New LiteralControl("<td class='text grey uppercase'><input type='radio' name='mcq" & n & "' value='D' />&nbsp;Answer D.</td></tr>"))

                    sql = "SELECT qAnswer FROM examTime.dbo.answer WHERE questionID = @qid ORDER BY NEWID()"
                    cmd.CommandText = sql
                    da.SelectCommand = cmd
                    da.Fill(dtmcqAns)
                    Dim arrAns As String()
                    arrAns = {dtmcqQC.Rows(0).Item(1), dtmcqAns.Rows(0).Item(0), dtmcqAns.Rows(1).Item(0), dtmcqAns.Rows(2).Item(0)}
                    arrAns = Functions.Functions.Shuffle(arrAns)
                    panelQContainer.Controls.Add(New LiteralControl("<tr><td class=""text blue"">" & arrAns(0) & "</td>"))
                    panelQContainer.Controls.Add(New LiteralControl("<td class=""text blue"">" & arrAns(1) & "</td>"))
                    panelQContainer.Controls.Add(New LiteralControl("<td class=""text blue"">" & arrAns(2) & "</td>"))
                    panelQContainer.Controls.Add(New LiteralControl("<td class=""text blue"">" & arrAns(3) & "</td></table>"))
                    If Not n = mcqCount Then
                        panelQContainer.Controls.Add(New LiteralControl("<div class='separator dark'></div>"))
                    End If
                    dtmcqQC.Clear()
                    dtmcqAns.Clear()
                Next
                panelQContainer.Controls.Add(New LiteralControl("</div>"))
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
End If

非常感谢您的帮助。 感谢。

0 个答案:

没有答案