hi,... everyone
i m trying to develop a page for online testing...
where test shuold be terminated when submit test button (asp server control) is clicked or when time is finished...
below code i have developed... before time limit, if i try to finish test by clicking on submit test button, it works properly...
but when time is finished.... the code doesn't work..
the code wich is written on click event of submit button, same code i have written on tick event (when time is finished)...
Partial Class Test
Inherits System.Web.UI.Page
Public ObjCon As New ConClass
Public TestPath As String
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
TestPath = ObjCon.GetTestPath()
Dim str As String
If Session("Ftime") Is Nothing Then
Dim TotalQue As Integer = Session("OptPattern").ToString().Length
Dim Qno As Integer = 1
Dim TotalOpt As Integer = 0
While (Qno <= TotalQue)
Dim TRQno As New HtmlTableRow
Dim TRQue As New HtmlTableRow
Dim TROpt As New HtmlTableRow
Dim TrHr As New HtmlTableRow
Dim TCQno As New HtmlTableCell
Dim TCQue As New HtmlTableCell
Dim TCOpt As New HtmlTableCell
Dim TcHr As New HtmlTableCell
TCQno.InnerText = "Question : " + Qno.ToString()
TRQno.Cells.Add(TCQno)
Dim TBox As New HtmlTextArea
TBox.Disabled = True
TBox.Rows = 10
TBox.Cols = 100
TBox.InnerText = File.ReadAllText(TestPath + Session("TestNo").ToString() + "_" + Qno.ToString() + ".txt")
TCQue.Controls.Add(TBox)
TRQue.Cells.Add(TCQue)
TotalOpt = Integer.Parse(Session("OptPattern").ToString().Chars(Qno - 1).ToString())
Dim ListOpt As New HtmlSelect
ListOpt.EnableViewState = True
ListOpt.ID = "ListOpt" + Qno.ToString()
ListOpt.Name = "ListOpt" + Qno.ToString()
ListOpt.Multiple = False
ListOpt.Size = TotalOpt
Dim i As Integer = 1
While (i <= TotalOpt)
str = File.ReadAllText(TestPath + Session("TestNo").ToString() + "_" + Qno.ToString() + "_" + i.ToString() + ".txt").ToString()
ListOpt.Items.Add(str)
i = i + 1
End While
TCOpt.Controls.Add(ListOpt)
TROpt.Cells.Add(TCOpt)
TableQuest.Rows.Add(TRQno)
TableQuest.Rows.Add(TRQue)
TableQuest.Rows.Add(TROpt)
Qno = Qno + 1
End While
End If
End Sub
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim min, sec As Integer
min = Integer.Parse(Session("Min").ToString())
sec = Integer.Parse(Session("Sec").ToString())
sec = sec - 1
If (sec < 0) Then
sec = 59
min = min - 1
End If
Session("min") = min
Session("sec") = sec
lblmin.Text = Session("min").ToString()
lblsec.Text = Session("sec").ToString()
Dim TotalQue As Integer = Session("OptPattern").ToString().Length
Dim Qno As Integer = 1
Dim Pattern As String = ""
Dim LOpt As New HtmlSelect // equivalent to Listbox control, but this one is html control...
While (Qno <= TotalQue)
LOpt.Items.Clear()
LOpt = Me.FindControl("ListOpt" + Qno.ToString())
Pattern = Pattern + (LOpt.SelectedIndex + 1).ToString()
'MsgBox("Qno : " + Qno.ToString() + vbCrLf + " Total options : " + LOpt.Items.Count.ToString() + vbCrLf + "Selectedd ans : " + LOpt.SelectedIndex.ToString())
Qno = Qno + 1
End While
Session("SPattern") = Pattern
If min <= 0 And sec <= 0 Then
SCore()
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Integer.Parse(Session("Min").ToString()) <= 0 And Integer.Parse(Session("Sec").ToString()) <= 0 Then
SCore()
End If
End Sub
Protected Sub btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click
Dim TotalQue As Integer = Session("OptPattern").ToString().Length
Dim Qno As Integer = 1
Dim Pattern As String = ""
Dim LOpt As New HtmlSelect
While (Qno <= TotalQue)
LOpt.Items.Clear()
LOpt = Me.FindControl("ListOpt" + Qno.ToString())
Pattern = Pattern + (LOpt.SelectedIndex + 1).ToString()
MsgBox("Qno : " + Qno.ToString() + vbCrLf + " Total options : " + LOpt.Items.Count.ToString() + vbCrLf + "Selectedd ans : " + LOpt.SelectedIndex.ToString()) // here it shows -1 as selected index, though all HtmlSelect controls are selected thats a main problem
Qno = Qno + 1
End While
Session("SPattern") = Pattern
SCore()
End Sub
Public Sub SCore()
MsgBox("At last in score" + vbCrLf + "rows : " + TableQuest.Rows.Count.ToString() + vbCrLf + "Pattern : " + Session("SPattern").ToString())
Session.Abandon()
Response.Redirect("~\Home.aspx")
End Sub
End Class