Online Exam in VB.NET

Unknown | 6:17 AM |


MasterPage.master



<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            height: 48px;
        }
        .style3
        {
            height: 448px;
        }
        .style4
        {
            height: 28px;
            font-weight: bold;
        }
        </style>
    <script type="text/javascript" language="javascript">
            javascript:window.history.forward(1);
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <table class="style1">
        <tr>
            <td align="center" class="style2"
                style="background-color: #6699FF; height: 50px; background-image: url('/C:/Users/Shreyas/Documents/Visual Studio 2008/WebSites/WebSite12/App_Data/mylogo.jpg');">
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style3" valign="top">
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
             
                    <table class="style1">
                        <tr>
                            <td style="background-color: #FFFF00; height: 10px;">
                                &nbsp;</td>
                        </tr>
                        <tr>
                            <td style="background-color: #FFCC99">
                                <br /><br /> <br /><br /> <br /> <br /><br /><br /><br /><br /> <br />
                                <br /><br /><br /><br /><br /> <br /> <br /> <br /> <br /> <br />                          <br />
                            </td>
                        </tr>
                        <tr>
                            <td style="background-color: #FFFF00; height: 10px">
                                &nbsp;</td>
                        </tr>
                    </table>            
                </asp:ContentPlaceHolder>
            </td>
        </tr>
        <tr>
            <td align="center" class="style4" style="background-color: #FF00FF">
                &nbsp;</td>
        </tr>
    </table>
    </form>
</body>
</html>


Default.aspx

<%@ Page Language="VB" MasterPageFile="~/SuccessPlus/Reception/OnlineExam/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
   
    <p>
    </p>
    <p>
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </p>
   
    <p align="center" >
        <br />
        WELCOME TO THE TEST</p>
    &nbsp;&nbsp;
    <p align="center" >
        This is a timed test.
    </p>
<p align="center" >
        You will be awarded 1 mark for every correct answer and no mark will be deducted
        for a wrong answer.</p>
<p align="center" >
        You have 60 seconds of time.</p>
    <p align="center">
        Please click the START button to begin the test.</p>
    <p></p> <p> </p> <p> </p> <p></p>
    <p align="center" >
        <asp:Button ID="Button1" runat="server" Text="START" Height="36px"
            Width="93px" />
    </p>
    <p>
    </p>
    <p>
        <marquee>ALL THE BEST</marquee>&nbsp;</p>
    <p>
    </p>
</asp:Content>

Default.aspx.vb


Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Label1.Text = "Welcome to the test, " & Request.QueryString("name")
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim h As New HttpCookie("start")
        'Set the time for the test here
        Dim dt As DateTime = Now.AddSeconds(60)
        h.Value = dt
        Response.Cookies.Add(h)
     
        Response.Redirect("default2.aspx")
    End Sub
End Class


Default2.aspx

<%@ Page Language="VB" MasterPageFile="~/SuccessPlus/Reception/OnlineExam/MasterPage.master" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p>
        <br />
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    </p>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" Interval="1000">
            </asp:Timer>
            <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
            <br />
        </ContentTemplate>
    </asp:UpdatePanel>
    <p>
        <asp:MultiView ID="MultiView1" runat="server">
            <asp:View ID="View1" runat="server">
                <br />
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                &nbsp;<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
                <br />
                <br />
                <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                </asp:RadioButtonList>
             
                <asp:Button ID="Button1" runat="server" Text="Previous" />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Button ID="Button2" runat="server" Text="Next" />                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
                <asp:Button ID="Button3" runat="server" Text="Show Marks" />
               
            </asp:View>
        </asp:MultiView>
    </p>
 
    <p align="left">
        &nbsp;</p>
     
</asp:Content>


Default2.aspx.vb

Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Data.SqlClient
Imports SpeechLib
Partial Class Default2
    Inherits System.Web.UI.Page
    Dim count As Integer
    Dim ans As String
    Dim a(6), t As Integer
    Dim adp As New SqlDataAdapter
    Dim ds As New DataSet
    Dim ctr As Integer
    Dim cls As Class1 = New Class1
    Dim db As connectionClass.connectionClass = New connectionClass.connectionClass
    Dim mydate As DateTime
    Dim cmd As New SqlCommand
    Dim dt As New DataTable
    Dim dr As DataRow
    Dim spo As New SpVoice

    Sub Show()
        Try

     
        dt = Session("Answered")
        If dt.Rows.Count <> 0 Then


            Dim v As View = Me.View1
            Dim l As Label
            l = CType(v.FindControl("Label1"), Label)
            l.Text = dt.Rows(ctr).Item("Serial") & "."
            l = CType(v.FindControl("Label2"), Label)
                l.Text = dt.Rows(ctr).Item("question")

                spo.Speak("Question is", SpeechVoiceSpeakFlags.SVSFlagsAsync)
                spo.WaitUntilDone(1000)
                spo.Speak(l.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync)
                spo.WaitUntilDone(1000)

            Dim r As RadioButtonList
            r = CType(v.FindControl("RadioButtonList1"), RadioButtonList)
            r.Items.Clear()
                r.Items.Add(dt.Rows(ctr).Item("choice1"))
                spo.Speak("First Option is", SpeechVoiceSpeakFlags.SVSFlagsAsync)
                spo.WaitUntilDone(1000)
                spo.Speak(r.Items(0).Text, SpeechVoiceSpeakFlags.SVSFlagsAsync)
                spo.WaitUntilDone(1000)
                r.Items.Add(dt.Rows(ctr).Item("choice2"))
                spo.Speak("Second Option is", SpeechVoiceSpeakFlags.SVSFlagsAsync)
                spo.WaitUntilDone(1000)
                spo.Speak(r.Items(1).Text, SpeechVoiceSpeakFlags.SVSFlagsAsync)
                spo.WaitUntilDone(1000)
                r.Items.Add(dt.Rows(ctr).Item("choice3"))
                spo.Speak("Third Option is", SpeechVoiceSpeakFlags.SVSFlagsAsync)
                spo.WaitUntilDone(1000)
                spo.Speak(r.Items(2).Text, SpeechVoiceSpeakFlags.SVSFlagsAsync)
                spo.WaitUntilDone(1000)
                r.Items.Add(dt.Rows(ctr).Item("choice4"))
                spo.Speak("Fourth Option is", SpeechVoiceSpeakFlags.SVSFlagsAsync)
                spo.WaitUntilDone(1000)
                spo.Speak(r.Items(3).Text, SpeechVoiceSpeakFlags.SVSFlagsAsync)
                spo.WaitUntilDone(1000)
            r.SelectedIndex = dt.Rows(ctr).Item("selected")
            Session("ctr") = ctr
            End If
        Catch ex As Exception

        End Try
    End Sub




    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim mydate2 As DateTime = Now
        Dim mydate3 As DateTime

        Try
            mydate3 = (mydate - mydate2).ToString
            Me.Label5.Text = "Time Left: " & mydate3.ToShortTimeString
        Catch ex As Exception
            Me.Label5.Text = "Error Setting up the Timer. Contact Admin"
        End Try

        If mydate3.ToShortTimeString = "00:00:00" Then

            Dim marks As Integer
            dt = Session("Answered")

            For Each x In dt.Rows
                If x("Selected") + 1 = x("correct") Then
                    marks += 1

                End If
            Next
            Response.Redirect("default3.aspx?marks=" & marks)

        End If
    End Sub

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

        mydate = Request.Cookies("start").Value



        If Not IsPostBack Then
            Me.MultiView1.ActiveViewIndex = 0
            cls.con.Open()
            cmd.Connection = cls.con

            Dim arbit As New Random
            Randomize()

            'X:
            ' For i = 0 To a.GetUpperBound(0)
            'For i = 0 To a.Length

            '    t = arbit.Next(1, 10)

            '    ' If Array.IndexOf(a, t) = -1 Then
            '    a(i) = t

            '    ' Else
            '    ' GoTo X
            '    ' End If

            'Next


            cmd.CommandText = "select count(*) from test"
            Dim count As Int64
            count = Int64.Parse(cmd.ExecuteScalar())



            For i = 0 To count
                cmd.CommandText = "select * from test where Serial=" & i & " order by Serial asc"
                adp.SelectCommand = cmd
                adp.Fill(ds, "test")
            Next

            cls.con.Close()

            dt = New DataTable("Answered")
            dt.Columns.Add("Serial", GetType(Integer))
            dt.Columns.Add("question", GetType(String))
            dt.Columns.Add("choice1", GetType(String))
            dt.Columns.Add("choice2", GetType(String))
            dt.Columns.Add("choice3", GetType(String))
            dt.Columns.Add("choice4", GetType(String))
            dt.Columns.Add("correct", GetType(String))
            dt.Columns.Add("selected", GetType(Integer))

            Dim r As DataRow

            For Each r In ds.Tables("test").Rows
                dr = dt.NewRow
                dr("Serial") = dt.Rows.Count + 1
                dr("question") = r.Item("question")
                dr("choice1") = r.Item("choice1")
                dr("choice2") = r.Item("choice2")
                dr("choice3") = r.Item("choice3")
                dr("choice4") = r.Item("choice4")
                dr("correct") = r.Item("correct")
                dr("selected") = -1
                dt.Rows.Add(dr)

            Next

            Session("Answered") = dt

            Call Show()



        End If

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

        ctr = Session("ctr")
        dt = Session("Answered")
        Session("ctr") = ctr
        ctr += 1
        Show()
        If ctr = 4 Then
            Me.Button2.Enabled = False

        End If
        Me.Button1.Enabled = True
    End Sub

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

        ctr = Session("ctr")
        dt = Session("Answered")
        ctr = ctr - 1
        If ctr = 0 Then
            Me.Button1.Enabled = False


        End If
        Session("ctr") = ctr
        Me.Button2.Enabled = True
        Show()

    End Sub

    Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged

        dt = Session("Answered")
        For Each drow In dt.Rows
            If drow("Serial") = Me.Label1.Text Then
                drow("Selected") = Me.RadioButtonList1.SelectedIndex
                Exit For


            End If
        Next

        Session("Answered") = dt


    End Sub




    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Try

       
        Dim marks As Integer
        dt = Session("Answered")

        For Each x In dt.Rows
            If x("Selected") + 1 = x("correct") Then
                marks += 1

            End If
        Next
        cls.con.Open()
        cmd = New SqlCommand("insert into ExamResult values('" & Session("cid") & "','" & marks & "' )", cls.con)
        cmd.ExecuteNonQuery()
        cls.con.Close()


            Response.Redirect("default3.aspx?marks=" & marks)
        Catch ex As Exception

        End Try
    End Sub


End Class


Default3.aspx

<%@ Page Language="VB" MasterPageFile="~/SuccessPlus/Reception/OnlineExam/MasterPage.master" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p>
        <br />
    </p>
    <p>
    </p>
    <p>
        Your Test Result is:
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
    </p>
    <p>
    </p>
    <p>
        You may now safely close the browser. Your result has been recorded.</p>
    <p>
    </p>
    <p>
    </p>
</asp:Content>

Default3.aspx.vb


Partial Class Default3
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Label2.Text = " " & Request.QueryString("marks")
        ' You may hold this in the DB to record the result

    End Sub
End Class

Default5.aspx

<%@ Page Language="VB" MasterPageFile="~/SuccessPlus/Reception/OnlineExam/MasterPage.master" AutoEventWireup="false" CodeFile="Default5.aspx.vb" Inherits="Default5" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style5
        {
            width: 98px;
            height: 41px;
            position: absolute;
            left: 474px;
            top: 287px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p>
        <br />
    </p>
    <p align="center" >Please Select Candidate ID to begin the Test
   
        &nbsp;<br /><br /></p>
    <p>
    </p>
       <p align="center" >
       
        Candidate ID:&nbsp;&nbsp;&nbsp;&nbsp;
           <asp:DropDownList ID="ddcandidate" runat="server" AutoPostBack="True">
           </asp:DropDownList>
    </p>
 <%--   <p align="center" >
       
        Username:&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </p>
    <p align="center" >
       
        Password:&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
    </p>--%>
    <p>
    </p>
    <p align="center" ><br /><br />
        <asp:Button ID="Button1" runat="server" Text="Submit" Height="39px"
            Width="111px" />
        </p>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
    <p>
    </p>
</asp:Content>

Default5.aspx.vb

Imports System.Data.SqlClient
Imports System.Data

Partial Class Default5
    Inherits System.Web.UI.Page
    Dim cls As Class1 = New Class1
    Dim db As connectionClass.connectionClass = New connectionClass.connectionClass
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        cls.con.Open()
        'Look at the login table for login credentials.
        'Dim cmd As New SqlCommand("Select * from Login where uname=@username and pwd=@password", cls.con)

        'cmd.Parameters.Add("@username", SqlDbType.VarChar)
        'cmd.Parameters("@username").Value = Me.TextBox1.Text

        'cmd.Parameters.Add("@password", SqlDbType.VarChar)
        'cmd.Parameters("@password").Value = Me.TextBox2.Text

        'Dim dr As SqlDataReader

        'dr = cmd.ExecuteReader

        'If dr.HasRows Then

        Dim cmd As New SqlCommand("select name from rip_candidate where cid=" & ddcandidate.SelectedValue, cls.con)
        Dim name As String
        name = cmd.ExecuteScalar().ToString()
        cls.con.Close()
        Session("cid") = ddcandidate.SelectedValue
        Response.Redirect("default.aspx?name=" & name)

        'End If

        cls.con.Close()


    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        loadcandidate()
    End Sub
    Public Sub loadcandidate()
        cls.con.Open()
        Dim cmd As New SqlCommand("select cid from rip_candidate", cls.con)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader()
        While dr.Read()
            ddcandidate.Items.Add(dr("cid"))
        End While
        dr.Close()
        cls.con.Close()

    End Sub

    Protected Sub ddcandidate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddcandidate.SelectedIndexChanged
     
    End Sub
End Class

Default6.aspx

<%@ Page Language="VB" MasterPageFile="~/SuccessPlus/Reception/OnlineExam/MasterPage.master" AutoEventWireup="false" CodeFile="Default6.aspx.vb" Inherits="Default6" title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server">
            </asp:Timer>
            <asp:Label ID="Label10" runat="server" Text="Label"></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
   
    <asp:Panel ID="Panel1" runat="server">
        <br />
        <asp:Label ID="Label11" runat="server" Text="Label"></asp:Label>
        &nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label12" runat="server" Text="Label"></asp:Label>
        <br />
        <br />
        <br />
        <br />
        <br />
        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        </asp:RadioButtonList>
        <br />
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button2" runat="server" Text="Button" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button3" runat="server" Text="Button" />
        <br />
   
   
   
    </asp:Panel>
</asp:Content>

Default6.aspx.vb

Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Data.SqlClient
Partial Class Default6
    Inherits System.Web.UI.Page


    Dim count As Integer
    Dim ans As String
    Dim a(4), t As Integer
    Dim adp As New SqlDataAdapter
    Dim ds As New DataSet
    Dim ctr As Integer
    Dim cls As Class1 = New Class1
    Dim db As connectionClass.connectionClass = New connectionClass.connectionClass
    Dim mydate As DateTime
    Dim cmd As New SqlCommand
    Dim dt As New DataTable
    Dim dr As DataRow

    Sub Show()
        dt = Session("Answered")
     
       
        Me.Label11.Text = dt.Rows(ctr).Item("Serial")

        Me.Label12.Text = dt.Rows(ctr).Item("question")



     
        Me.RadioButtonList1.Items.Clear()
        Me.RadioButtonList1.Items.Add(dt.Rows(ctr).Item("choice1"))
        Me.RadioButtonList1.Items.Add(dt.Rows(ctr).Item("choice2"))
        Me.RadioButtonList1.Items.Add(dt.Rows(ctr).Item("choice3"))
        Me.RadioButtonList1.Items.Add(dt.Rows(ctr).Item("choice4"))
        Me.RadioButtonList1.SelectedIndex = dt.Rows(ctr).Item("selected")



        Session("ctr") = ctr
    End Sub




    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim mydate2 As DateTime = Now
        Dim mydate3 As DateTime

        Try
            mydate3 = (mydate - mydate2).ToString
            Me.Label10.Text = "Time Left: " & mydate3.ToShortTimeString
        Catch ex As Exception
            Me.Label10.Text = "Error Setting up the Timer. Contact Admin"
        End Try

        If mydate3.ToShortTimeString = "00:00:00" Then
            Response.Redirect("default3.aspx")
        End If
    End Sub

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

        mydate = Request.Cookies("start").Value



        If Not IsPostBack Then
            cls.con.Open()
            cmd.Connection = cls.con

            For j = 0 To Session.Keys.Count - 1
                a(j) = Session.Keys(j)

            Next


            For i = 0 To 4
                cmd.CommandText = "select * from test where Serial=" & a(i)
                adp.SelectCommand = cmd
                adp.Fill(ds, "test")
            Next

            cls.con.Close()

            dt = New DataTable("Answered")
            dt.Columns.Add("Serial", GetType(Integer))
            dt.Columns.Add("question", GetType(String))
            dt.Columns.Add("choice1", GetType(String))
            dt.Columns.Add("choice2", GetType(String))
            dt.Columns.Add("choice3", GetType(String))
            dt.Columns.Add("choice4", GetType(String))
            dt.Columns.Add("correct", GetType(String))
            dt.Columns.Add("selected", GetType(Integer))

            Dim r As DataRow

            For Each r In ds.Tables("test").Rows
                dr = dt.NewRow
                dr("Serial") = dt.Rows.Count + 1
                dr("question") = r.Item("question")
                dr("choice1") = r.Item("choice1")
                dr("choice2") = r.Item("choice2")
                dr("choice3") = r.Item("choice3")
                dr("choice4") = r.Item("choice4")
                dr("correct") = r.Item("correct")
                dr("selected") = -1

            Next

            Session("Answered") = dt

            'Call Show()


        End If
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        'Me.Label4.Visible = False
        ctr = Session("ctr")
        dt = Session("Answered")
        Session("ctr") = ctr
        Show()
        ctr += 1
        If ctr = 4 Then
            Me.Button2.Enabled = False
            'Me.Label3.Text = "LAST QUESTION"
        End If
        'Me.Button1.Enabled = True
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Me.Label3.Visible = False
        ctr = Session("ctr")
        dt = Session("Answered")
        ctr = ctr - 1
        If ctr = 0 Then
            Me.Button1.Enabled = False
            'Me.Label4.Text = "FIRST QUESTION"

        End If
        Session("ctr") = ctr
        Me.Button2.Enabled = True
        Show()

    End Sub

    Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged

        dt = Session("Answered")
        For Each drow In dt.Rows
            If drow("Serial") = Me.Label11.Text Then
                drow("Selected") = Me.RadioButtonList1.SelectedIndex
                Exit For


            End If
        Next

        Session("Answered") = dt


    End Sub




    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim marks As Integer
        dt = Session("Answered")

        For Each x In dt.Rows
            If x("Selected") + 1 = x("correct") Then
                marks += 2

            End If
        Next
        Response.Redirect("default3.aspx?marks=" & marks)
    End Sub
End Class

Disable Back Button in asp.net using Javascript..............................

<script type="text/javascript">
     var storedHash = window.location.href;
     function changeHashOnLoad() {
         window.location.href += "#";
         setTimeout("changeHashAgain()", "50");
     }

     function changeHashAgain() {
         window.location.href += "1";
     }


     window.setInterval(function () {
         if (window.location.href != storedHash + "#") {
             window.location.href = storedHash + "#";
         }
     }, 50);

     function noBack() { window.history.forward(1); }
    </script>


<body style="background: White;"  onload="changeHashOnLoad();" onunload="" onpageshow="if (event.persisted) noBack();">
</body>

Send mail with image in body in asp.net with c#......................

mailContent = "<table cellspacing='1' cellpadding='1' width='600' border='0'>" +
               "<tr><td align='left' style='height: 25px; font-weight: bold; font-size: 8pt; color: Black; font-family:Verdana; background-color: #ffffff'><hr style='width:100%; color: #8DC63F; background-color: #8DC63F; height: 1px;'/></td></tr>" +
               "<tr>" +
"<td align='left' style='height: 250px; font-weight: bold; font-size: 8pt; color: Black; font-family:Verdana;vertical-align: top;'>" +
"<img src='http://www.gccstars.com/mail/mails.jpg' style='width: 250px; height: 250px;' width='0' />" +

 "</td>" +
 "</tr>" +
               "<tr><td align='left'>" +

               "<table cellspacing='1' cellpadding='1' border='0'>" +
               "<tr><td align='left' style='height: 25px; font-weight: bold; font-size: 8pt; color: Black; font-family:Verdana; vertical-align: top;'>Name: </td><td align='left' style='height: 25px; font-weight: bold; font-size: 8pt; color: Black; font-family:Verdana; vertical-align: top;'>" + fullname + "</td></tr>" +
               "<tr><td align='left' style='height: 25px; font-weight: bold; font-size: 8pt; color: Black; font-family:Verdana; vertical-align: top;'>Email Id: </td><td align='left' style='height: 25px; font-weight: bold; font-size: 8pt; color: Black; font-family:Verdana; vertical-align: top;'>" + memmail + "</td></tr>" +
                         
                           "<tr><td align='left' style='height: 25px; font-weight: bold; font-size: 8pt; color: Black; font-family:Verdana; vertical-align: top;'>Password: </td><td align='left' style='height: 25px; font-weight: bold; font-size: 8pt; color: Black; font-family:Verdana; vertical-align: top;'>" + pwd + "</td></tr>" +
                           "<tr><td align='left' style='height: 25px; font-weight: bold; font-size: 8pt; color: Black; font-family:Verdana; vertical-align: top;'>" + body + "</td></tr>" +
                       

               "</table>" +

               "</td></tr>" +
               "</table>";

MessageBox in asp.net using Javascript and c#.................

 ScriptManager.RegisterStartupScript(this, this.GetType(), "new", "alert('Data saved successfully!');", true);

Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....