13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

138<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>Once you have the <strong>ASP</strong>.<strong>NET</strong> portion <strong>com</strong>plete, open the Cbox.aspx.cs file from theSolution Explorer. As you will see, just as with the HTML Checkbox form, you can usethe same algorithm with the ternary conditional to extract the data from the web control.However, note that the property is Text instead of Value as it is in the HTML version.The following code snippet shows the basic line of code for data extraction:myVariable = CheckBox1.Checked == true ? CheckBox1.Text: null;The rest of the C# portion of the application is likewise similar to the CheckBox’s HTMLcousin:C# Cbox.aspx.csusing System;public partial class Cbox : System.Web.UI.Page{private String cabinet;protected void Button1_Click(object sender, EventArgs e){cabinet = "Your cabinet is:";cabinet += CheckBox1.Checked == true ? "--" + CheckBox1.Text +"" : null;cabinet += CheckBox2.Checked == true ? "--" + CheckBox2.Text +"" : null;cabinet += CheckBox3.Checked == true ? "--" + CheckBox3.Text +"" : null;cabinet += CheckBox4.Checked == true ? "--" + CheckBox4.Text +"" : null;Label1.Text = cabinet;}}Once you finish, test the application. Figure 6-7 shows what you should see.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!