Welcome to MSDN Blogs Sign in | Join | Help

A sa(i)mple Online Exam Engine on ASP.NET

Some time ago, a customer that attended my MSDN session, asked me to help him developing an online exam engine. They wanted something simple that retrieved questions from a database or a file and allowed employees to take some online exams. In order to simplify deployment, they wanted to do this on ASP.NET and SQL Server.

As I browsed in the internet, I did find a few samples but none that completely satisfied me. So, for the exercise, I decided to develop my own sample in a way that each of its components could be changed with ease. So, I decided to use a standard three tier model: presentation, business logic and data access.

For the presentation layer, I decided to use a simple ASP.NET web user control (ascx). This allows you to simply drag the control to your page to use it and also allows you to customize the display with the help of the VS.NET IDE.

The business logic layer is the one that I believe you will not want to change much. Possibly add a few things. I did the sample for illustration purposes. It's not intended to be a full-scale online exam engine, but rather a starting point for developing your own.

The data access layer is actually the one you WILL want to change. In order to get the sample working in a way you can test it with ease, I retrieve the exam questions from an xml file. I built this layer (QuestionRetriever.cs) in a way that it uses very simple methods to get simple pieces of information (number of questions, get question number x, time limit for this exam, etc.) so you shouldn't have any problems changing this methods to get the same data from a SQL server or another database engine.

This was the main concern when developing the sample: build the exam engine in a way that the physical location of the data is irrelevant.

You can test the sample here: http://nunosilva.members.winisp.net/samples/working/OnlineExamEngine/

The xml file that is used to generate this exam can be found here: http://nunosilva.members.winisp.net/samples/working/OnlineExamEngine/math.xml

The zip file containing the sample can be found here: http://nunosilva.members.winisp.net/samples/OnlineExamEngine.zip

Drilling down a bit, let's look at some of the main features here:

The ascx basically is responsible for displaying the exam from start to finish. To use it, you simply drag and drop it into a page. Then you must declare it in your code-behind file. The only thing that I don’t like here is you have to name it myQuestion1…

Why? Well, I do use some JavaScript to implement the timer. We set the timer to an initial value, the timer decrements itself each second and when it reaches 0, disables the buttons and sends the user to the scoring report. To implement this, and because I’m not a JavaScript expert, I have to reference the buttons and other controls on the page by its id. The problem is that, because we’re in a user control, ASP.NET renders all controls inside it with the user control name as a prefix (e.g. myQuestion1_timer) to avoid collisions. So, when I need to reference a control in JavaScript by its id, I have to make sure the user control name is a particular one. Of course you can choose another name but you’ll have to change the JavaScript yourself. By the way, if someone has a suggestion on how to change this please post a comment to this post.

After you declare the control, you set a property called exam_url that specifies where the exam file (xml) is located. One way to quickly change this to SQL server is setting this property to the exam id on the database and change the data access layer to access the database instead of a file.

Buy as far as using the sample as is that’s all you have to do: put the control on the page and specify where the exam is found. Nice!

The business logic tier defines a set of classes that encapsulate all the exams logic. It has objects that represent a question, an answer and has all the logic needed to advance to next question, score the exam, etc.

The code is pretty self-explanatory although there are some tricks I had to use mostly related to the interaction between the JavaScript timer and my server side code. However, of course you are free to ask me questions about this sample.

 

Hope this code might prove useful to you.

Published Thursday, February 17, 2005 11:33 AM by nunos
Filed under:

Comments

Thursday, February 17, 2005 12:44 PM by Michal

# re: A sa(i)mple Online Exam Engine on ASP.NET

You could look at ClientID property of System.Web.UI.Control class. It gives you a client-side ID generated by ASP.NET. You can use it for generating a JavaScript code not depending on hardcoded names.

Regards,
Michal
chaniewski@gmail.spamannoysme.com
Friday, February 18, 2005 10:26 AM by Nuno Silva

# re: A sa(i)mple Online Exam Engine on ASP.NET

Thanks...that works...though I seem to recall trying that and hiting another problem later on. However, it's been a while since I developed this sample so I'll try to implement it in the next few days and post an updated code here.

Best Regards
Nuno Silva
nunos@microsoft.com
Saturday, February 26, 2005 7:15 AM by venkat

# re: A sa(i)mple Online Exam Engine on ASP.NET

hello

# nunos s Blog A sa i mple Online Exam Engine on ASP NET | Quick Diets

Anonymous comments are disabled
 
Page view tracker