Online Test Website in ASP
Online Test Website in ASP
NET using C#
and SQL Server Database
If you love my work
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Online Test </title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"
type="text/javascript"></script>
<script>
function StartTest(popUpPage) {
window.open(popUpPage, 'null',
'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,fullscreen=yes');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div style=" text-align :center; width:100%">
</div>
</form>
</body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"
type="text/javascript"></script>
</head>
<body oncontextmenu="return false" style=" background: #cccca0;">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManger" runat="server"></asp:ScriptManager>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
CssClass="btn" OnClientClick="return CheckIfAllQuestionAnswerHasBeenSubmitted()" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<script>
//Set the number of minutes you need
var mins = 1;
var secs = mins * 60;
var currentSeconds = 0;
var currentMinutes = 0;
var ourtimer;
function StartCountDown() {
ourtimer = setTimeout(Decrement, 1000);
}
function EndCountDown() {
clearTimeout(ourtimer);
}
function Decrement() {
currentMinutes = Math.floor(secs / 60);
currentSeconds = secs % 60;
if (currentSeconds <= 9) currentSeconds = "0" + currentSeconds;
secs--;
document.getElementById("timerText").innerHTML = "Time Remaining " +
currentMinutes + ":" + currentSeconds;
if (secs !== -1) {
setTimeout('Decrement()', 1000);
}
else {
window.location.href = "default.aspx?timeout=1"
}
}
function CheckIfAllQuestionAnswerHasBeenSubmitted() {
var numItems = $('.tblOptions').length;
var flagtocheckcount = 0;
$(".tblOptions").each(function () {
var groupname = $('input[type=radio]:first', this).attr('name');
if (!$("input[name='" + groupname + "']:checked").val()) {
$(this).parents(".tableclass").addClass("border");
var tableid = $(this).closest('table
[class^="tableclass"]').attr("id");
}
else {
flagtocheckcount = flagtocheckcount + 1;
}
})
if (parseInt(flagtocheckcount) == parseInt(numItems)) {
var CountFinalResult = 0;
$(".tblOptions").each(function () {
var groupname = $('input[type=radio]:first',
this).attr('name');
var radioId = $("input[name='" + groupname +
"']:checked").attr("id")
var UserSelectedAnswer = $("label[for='" + radioId +
"']").text();
var CorrectAnswer = $('span:last-child', this).text();
var CorrectAnswerSpanId = $('span:last-child',
this).attr("id");
var QuestionStatus = $("span:nth-last-child(1)",
this).attr("id");
if (CorrectAnswer == UserSelectedAnswer) {
$("#" + QuestionStatus).text("Correct
Answer").css("color", "green");
$('td.correctAnswer').find("td.correctAnswer",
this).css("display", "none");
CountFinalResult = CountFinalResult + 1;
}
else {
//$('table.tblOptions tbody tr td:last-
child').addClass("incorrect");
$('span:last-child', this).css({ 'display': 'inline-flex'
});
$("#" + QuestionStatus).text("InCorrect Answer").css({
'color': 'Red' });
$('td.correctAnswer', this).css({ "display": "block",
"background-color": "yellow", "color": "red" });
}
});
$("#lbresult").text("Final Result-:" + CountFinalResult + "/7");
$("#btnSubmit").attr("disabled", "disabled"); //disable button if
all questions answer has been given
$("#btnSubmit").removeClass("btn");
$("#btnSubmit").addClass("btndiabled");
EndCountDown();
$("#timerText").css("display", "none");
$("#spnthankyou").append("Thank You for submitting your test.")
$("input[type=radio]").attr('disabled', true); //disable all
radio button after test submitted by user
return false;
}
else {
return false;
}
}
function CheckTheCountOfQuestionHasBeenAnswered() {
TotalQuestions = $('.tblOptions').length;
var TotalGivenAnswerCount = 0;
var flagtocheckcount = 0;
$(".tblOptions").each(function () {
var groupname = $('input[type=radio]:first', this).attr('name');
if (!$("input[name='" + groupname + "']:checked").val()) {
}
else {
TotalGivenAnswerCount = TotalGivenAnswerCount + 1;
}
})
CountCheckCheckQuestion = TotalGivenAnswerCount;
}
</script>
<style>
.border {
border-color: red;
border-width: 2px;
border-style: solid;
width: 100%;
}
.correctAnswer {
display: none;
width: 950px!important;
}
.tblOptions {
width: 100%;
}
.btn {
background: #000000;
background-image: -webkit-linear-gradient(top, #000000, #2980b9);
background-image: -moz-linear-gradient(top, #000000, #2980b9);
background-image: -o-linear-gradient(top, #000000, #2980b9);
background-image: linear-gradient(to bottom, #000000, #2980b9);
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 6px;
font-family: Arial;
color: #ffffff;
font-size: 19px;
padding: 3px 20px;
text-decoration: none;
}
.btn:hover {
background: #261c61;
background-image: -webkit-linear-gradient(top, #261c61, #3498db);
background-image: -moz-linear-gradient(top, #261c61, #3498db);
background-image: -o-linear-gradient(top, #261c61, #3498db);
background-image: linear-gradient(to bottom, #261c61, #3498db);
text-decoration: none;
cursor: pointer;
}
.btndiabled {
background: #bdb3bd;
background-image: -webkit-linear-gradient(top, #bdb3bd, #757575);
background-image: -moz-linear-gradient(top, #bdb3bd, #757575);
background-image: -o-linear-gradient(top, #bdb3bd, #757575);
background-image: linear-gradient(to bottom, #bdb3bd, #757575);
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 6px;
font-family: Arial;
color: #ffffff;
font-size: 19px;
padding: 3px 20px;
text-decoration: none;
cursor: none;
}
</style>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;