ASP.NET Basics (Part 7): Command and Control - Test Drive (Page 4 of 7 ) Just as you can access data from text fields in an ASP.NET script, you can also evaluate the state of radio buttons and list boxes. To demonstrate, let's create a more complex form.
<html> <head> <basefont face=arial> </head>
<body> <h2> Survey</h2>
<form action="result.aspx" method="POST">
<p>
Do you plan to buy a car? <input type="radio" value="Y" name="buycar">Yes <input type="radio" value="N" name="buycar">No
<p>
What is your budget for the car, if you were to buy one? <select name="budget"> <option value="5" selected>> $1,000,000</option> <option value="4">> $500,000 and < $1,000,000 </option> <option value="3">> $250,000 and < $500,000</option> <option value="2">> $100,000 and < $250,000</option> <option value="1"> < $100,000</option> </select>
<p> <input type="submit" value="Submit Feedback">
</form>
</body> </html>
And here's "result.aspx".
<script language="c#" runat="server"> void Page_Load() { // result.aspx
// define the variables and assign values string budget_string = Request.Form["budget"]; string buycar = Request.Form["buycar"];
// convert string to number int budget = Convert.ToInt32(budget_string);
// process and display
// "Y" to buying a car if (buycar == "Y") { if(budget > 3) { output.Text = "So you're looking for a Ferrari or a Porsche, hmmm?"; } else { output.Text = "We have the latest models from Ford and GM available for a test drive"; } } else { output.Text = "Hey, why not? Everybody has one these days..."; }
} </script> <html> <head> <basefont face="Arial"> </head> <body> <center><asp:label id="output" runat="server" /></center> </body> </html>
As you can see, evaluating radio buttons and list boxes is almost exactly the same as evaluating regular text fields. Next: The Taste Test >>
More ASP.NET Articles More By Harish Kamath (c) Melonfire |