Developing Conditionally Driven Event Handlers in ASP.NET 3.5
What is a conditionally-driven event handler, and why would you want to use one? Basically, such an event handler will perform its assigned action -- such as displaying text on the screen -- if and only if a certain specified condition is met. As you might imagine, such event handlers have a range of uses. This article will walk you through some examples in ASP.NET 3.5.
You should have gained a basic understanding and formulation of event handlers in ASP.NET from this tutorial. Now if you need to go more deeply into this aspect of developing ASP.NET 3.5 web applications, one of the most important tools you can use is "conditionally driven" event handlers.
Let's consider one of the examples given in a previous tutorial, namely the web application to compute the area of the circle. Suppose you want to alter the project and say the application can only compute the areas of circles with radii greater than 100 and rejects values below that. You will need to employ some kind of conditional server side scripting which will analyze user inputs. And then it will fire the event depending on the user input. This is an example of a conditionally-driven "click" event handler.
Other types of event handlers discussed are the "page load" type of handlers. This will fire the event at any time the page is requested to the server. To make conditionally-driven page load handlers, server side scripting will analyze user inputs are needed, in a way that is similar to what is done in click event processing.
For example, say you are going to make an application which will display "Good morning" in the browser if the server time is 6 AM or "Good evening" if the server time is 8 PM. Things like this need to have some conditional statements added to your ASP.NET server side scripts.
In this tutorial, as in other ASP.NET tutorials for beginners or intermediate developers using the .NET framework, the recommended language to use for server side scripting is Visual Basic. There are other options, such as Visual C#, but that language is not recommended for first time readers or beginning learners of ASP.NET.
Below is an important distinction between these two programming languages that are used in ASP.NET:
The conditional programming statements in this tutorial will be developed using Visual Basic.
Developing IQ Test Online Using ASP.NET 3.5
To aid the learning process, let's have an example. Say you would like to develop an ASP.NET 3.5 web application equivalent to the online PHP IQ test featured in another tutorial. To recap, it is a 10-item IQ quiz that will measure a person's intelligence in terms of IQ (Intelligence Quotient). The formula for computing IQ is:
IQ = (mental age / chronological age) * 100
First, the form should asked for the user's chronological age, that is, the age of the person. And then the user can proceed to answer the quiz's questions. Finally, once the answers are submitted to ASP.NET, the script will assign scores depending on the difficulty of the question, and then compute the mental age, which will then be used to compute the person's IQ.
You will need to create a web form that will be very similar to the PHP version. By design, it should like the screen shot below:
The principles and skills needed to construct this web form along with its variables are discussed in this tutorial. Please refer to it for details. The only important thing that you need to note is the ID of those variables. In this example, you should let:
age= id representing the age
test1= id representing the answer of test1
test2= id representing the answer of test2
and so on...
submitbutton = id representing the form submit button.
iqresult = id representing the text label (for displaying the results).
Default.aspx = ASP.NET web page containing the web form
The text box web control is easy to create. You will only need to click and drag the web control elements from the Visual Web Developer toolbox to the Default.aspx source code.
In addition, the text label web control (for displaying the results to the browser) should be placed after the </form> tag since it is not part of the web form.
The final web form HTML, after you've completed the click-and-drag procedure, should look like this, with all fonts in Verdana:
Test question 9: If you are using Excel, which function offers the most convenient and most popular approach for extracting data from other spreadsheets or workbooks without using the manual copy and paste method. This is a one word answer.
Test question 10: If a 65 year old couple retires today how much may they need today to cover their future health care cost? This answer is only a figure and does not include a dollar sign.