⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 questions.aspx.vb

📁 一个在线考试系统
💻 VB
字号:

Partial Class questions
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        questionDetails.DataBind()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles buttonNext.Click

        Try
            ' Save off previous answers
            Dim dr As System.Data.DataRowView
            dr = CType(questionDetails.DataItem, System.Data.DataRowView)

            ' Create Answer object to save values
            Dim a As Answer = New Answer()
            a.QuestionID = dr("QuestionOrder").ToString()
            a.CorrectAnswer = dr("CorrectAnswer").ToString()
            a.UserAnswer = answerDropDownList.SelectedValue.ToString()

            Dim al As ArrayList
            al = CType(Session("AnswerList"), ArrayList)
            al.Add(a)

            Session.Add("AnswerList", al)

        Catch ex As Exception
            ' Sometimes the most difficult decisions involve 
            ' trying to figure out what should you as a developer
            ' should do for your user's experience as bad 
            ' things happen within your application.
            ' This requires a little empathy ... I recommend a
            ' quick coffee break while you imagine what
            ' *you* would want to happen if you were half-way
            ' through the quiz and something "screwed-up" on
            ' the server (server reset, etc.)

            ' In my 'try' statement I have two potential problems.
            ' 1st, what if the app can't pull the questions 
            ' from the database for some reason?  2nd, what if
            ' the web server can't retrieve the current user's
            ' session data?  In both cases, I could construct 
            ' some elaborate work arounds to safeguard against this
            ' from ever happening, or if I really thought
            ' this was going to be a huge issue, I could back
            ' up and re-think how I'm persisting the user's
            ' answers during the quiz.  However, since my goal
            ' here is to keep this example application simple,
            ' I'm merely going to return the user to the 
            ' default.aspx page.  Please keep in mind that I'm
            ' not satisfied with this because I think it "surprises"
            ' and potentially diminishes the quality of the user's
            ' experience with my application, however I have some 
            ' time constraints in this tutorial.

            Response.Redirect("default.aspx")
        End Try

        If questionDetails.PageIndex = questionDetails.PageCount - 1 Then
            ' Go to evaluate answers
            Response.Redirect("results.aspx")
        Else
            questionDetails.PageIndex += 1
        End If

        If questionDetails.PageIndex = questionDetails.PageCount - 1 Then
            buttonNext.Text = "Finished"
        End If

    End Sub

    Sub Page_PreInit(ByVal sender As Object, ByVal e As EventArgs) Handles Me.PreInit

        If Profile.IsAnonymous = False Then
            If Profile.Theme <> "" Then
                Page.Theme = Profile.Theme
            End If
        Else
            Response.Redirect("default.aspx")
        End If
    End Sub

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -