WEB460 Lab 1 of 7: Basic ASP Page and Cross-Page Posting

Availability: In stock

Regular Price: $12.00

Special Price: $10.00

OR

WEB460 Lab 1 of 7 Basic ASP Page and Cross-Page Posting CheckOut Page

Double click on above image to view full picture

Zoom Out
Zoom In

More Views

Quick Overview

WEB460 Lab 1 of 7: Basic ASP Page and Cross-Page Posting


Scenario/Summary
In this week's lab assignment, we'll be developing credit card information checkout pages of an online book store. Such pages are necessary in any developed e-commerce application. In these pages, users are required to enter information related to their payment and shipping options.
We will develop two pages. On the first page, the user provides personal, payment, and shipping information for the order submitted. The second page summarizes the user's input and requires the user to confirm.


Learning Objectives
Create an ASP.NET web project in Visual Studio 2010 or Visual Studio 2012.
Create and design ASP.Net web forms.
Cross-page posting in ASP.NET
How to use ASP.NET web server controls (DropDownList, TextBox, RadioButtonList, Label, and Button)
Exception handling


Deliverables
A zip archive of the ASP.NET Application implementing cross-page posting consisting of the following files:
– pgCheckOut.aspx web form with all server controls defined in requirements
– pgCheckOut.aspx.cs with code for cross-page posting
– pgConfirm.aspx web form with all server controls defined in requirements
– pgConfirm.aspx.cs with code for cross-page posting and exception handling


Lab Steps
STEP A: Create a New Web Site Project
1. Go to the File menu and select New. From the New sub-menu, select Web Site to create a new Web Site project.
2. In the New Web Site dialog box, select the language you want to use in developing your web application; for our applications choose Visual C#.
3. Select ASP.NET Empty Web Site to create a project with only a web.config file.
4. Then specify the location of your project or website. Note that in ASP.NET, you have the option of creating your website in different locations, whether in any folder on your local file system, on the local IIS server you have on your computer, or on a remote HTTP or FTP server. ASP.NET has an integrated IIS server with the Visual Studio .Net IDE.
I recommend using the default Web Sites folder in the Visual Studio project folder. This allows the development of web applications without the hassle of setting up an IIS server on your computer. If you don't have IIS server installed on your computer, this is the best option to select for your lab.


STEP B: Create and Design a New Web Form, pgCheckOut.aspx
1. Add the first web form to the web application by right-clicking on the project name and selecting Add New Item. Name the web form pgCheckOut.aspx.
2. Add the controls in the table below to the form. If desired, you can visually layout the form using HTML and CSS after adding the controls.
The first column in the table shows the data the control represents or their label, the second column is the type of control, and the last column is the ID or name of the actual control. If the Visual Studio web form Toolbox Pane is not displayed, you can show it by going to the View menu and selecting Toolbox. All of these controls can be found in the Toolbox Pane.
Data or Label Control Type Control ID or Name
First Name TextBox txtFirstName
Last Name TextBox txtLastName
Street TextBox txtStreet
City TextBox txtCity
State TextBox txtState
Payment Method RadioButtonList rblCCType
Credit Card Number TextBox txtCCNumber
Submit Button btnSubmit
Phone Number TextBox txtPhone


3. When the user clicks on the submit button, pgConfirm.aspx should be displayed. This is done with cross-page posting. To implement this, set the PostBackUrl property of the Submit button to ~/pgConfirm.aspx. This will cause the pgCheckOut.aspx to post user requests to the web page pgConfirm.aspx, which we will create shortly.


STEP C: Add Code to the pgCheckOut.aspx Form (to Read User Input and Implement Cross-page Posting)
Implement public methods in the pgCheckOut.aspx.cs code file to expose the form's control values to other pages. The code below is an example of how to retrieve the value of the txtFirstName and txtLastName.
Sample Method to Get Control Values
public TextBox FirstName
{ get { return txtFirstName; } }
public TextBox LastName
{ get { return txtLastName; } }


STEP D: Create and Design Another Web Form, pgConfirm.aspx
1. Add the second web form to your web application. Name the form pgConfirm.aspx.
2. Add label controls to display the user input values for the name, address, credit card type, and credit card number.
This allows the user to review and confirm order information before final submission. Add the controls in the table below to the form. The application will fill in the text displayed by the labels, so you don't need to. You should provide additional labels that describe these values for the user.
Control Type Control ID or Name Control Purpose
Label lblName Holds the concatenation string of first name and last name entered in pgChekout.aspx
Label lblAddress Holds the concatenation of all address-related fields user input in pgCheckOut.aspx
Label lblCCType Displays the credit card type the user selected in pgCheckOut.aspx
Label lblCCNumber Displays the credit card number the user entered in pgCheckOut.aspx
Label lblStatus Displays the message of any run time exception that might happen during run time
Button btnSubmit When the user clicks on the submit order button, this displays a note to the user that his or her order was submitted successfully. You should use the status label to display the message.


STEP E: Add Code to the pgConfirm.aspx Form (to Allow User to Verify Order Input and Submit for Final Processing)
1. In the pgConfirm.aspx page, add the following code to the PreviousPageType directive to the pgConfirm.aspx file, and set it to the pgCheckOut.aspx.
<%@ Page Language="C#" AutoEventWireup=“true" CodeFile="pgConfirm.aspx.cs" Inherits="pgConfirm" %>
<%@ PreviousPageType VirtualPath="~/pgCheckOut.aspx" %>
2. Next, in the Page_Load() event of the pgConfirm.aspx.cs code page, check whether there is any cross-page posting by checking whether there is a cross-page postback, and set the values of the label controls with the corresponding user input values from the previous page as shown below. Be sure to implement for all controls on the form.
3. Enclose your code in a try/catch block to handle any run time exception thrown by the application for any reason, as shown below.
4. Add code to have lblStatus display the message of any thrown exception. Don't forget to add comments explaining what each line of code does.
pgConfirm Page_Load method
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (PreviousPage.IsCrossPagePostBack)
{
lblName.Text = PreviousPage.FirstName.Text + " " + PreviousPage.LastName.Text;
// Your code to set other form labels goes here
}
}
catch (Exception error )
{
lblStatus.Text = error.Message;
}
}


STEP F: Compile, Test, Save, and Submit Your Project
1. Save your work!
2. Test it! Make changes as appropriate until it works.
3. Remember to add comments for each step being performed.
4. Please zip and submit the entire web project folder.

Regular Price: $12.00

Special Price: $10.00

Details

WEB460 Lab 1 of 7: Basic ASP Page and Cross-Page Posting

Scenario/Summary
In this week's lab assignment, we'll be developing credit card information checkout pages of an online book store. Such pages are necessary in any developed e-commerce application. In these pages, users are required to enter information related to their payment and shipping options.
We will develop two pages. On the first page, the user provides personal, payment, and shipping information for the order submitted. The second page summarizes the user's input and requires the user to confirm.

Learning Objectives
Create an ASP.NET web project in Visual Studio 2010 or Visual Studio 2012.
Create and design ASP.Net web forms.
Cross-page posting in ASP.NET
How to use ASP.NET web server controls (DropDownList, TextBox, RadioButtonList, Label, and Button)
Exception handling

Deliverables
A zip archive of the ASP.NET Application implementing cross-page posting consisting of the following files:
– pgCheckOut.aspx web form with all server controls defined in requirements
– pgCheckOut.aspx.cs with code for cross-page posting
– pgConfirm.aspx web form with all server controls defined in requirements
– pgConfirm.aspx.cs with code for cross-page posting and exception handling

Lab Steps
STEP A: Create a New Web Site Project
1. Go to the File menu and select New. From the New sub-menu, select Web Site to create a new Web Site project.
2. In the New Web Site dialog box, select the language you want to use in developing your web application; for our applications choose Visual C#.
3. Select ASP.NET Empty Web Site to create a project with only a web.config file.
4. Then specify the location of your project or website. Note that in ASP.NET, you have the option of creating your website in different locations, whether in any folder on your local file system, on the local IIS server you have on your computer, or on a remote HTTP or FTP server. ASP.NET has an integrated IIS server with the Visual Studio .Net IDE.
I recommend using the default Web Sites folder in the Visual Studio project folder. This allows the development of web applications without the hassle of setting up an IIS server on your computer. If you don't have IIS server installed on your computer, this is the best option to select for your lab.

STEP B: Create and Design a New Web Form, pgCheckOut.aspx
1. Add the first web form to the web application by right-clicking on the project name and selecting Add New Item. Name the web form pgCheckOut.aspx.
2. Add the controls in the table below to the form. If desired, you can visually layout the form using HTML and CSS after adding the controls.
The first column in the table shows the data the control represents or their label, the second column is the type of control, and the last column is the ID or name of the actual control. If the Visual Studio web form Toolbox Pane is not displayed, you can show it by going to the View menu and selecting Toolbox. All of these controls can be found in the Toolbox Pane.
Data or Label Control Type Control ID or Name
First Name TextBox txtFirstName
Last Name TextBox txtLastName
Street TextBox txtStreet
City TextBox txtCity
State TextBox txtState
Payment Method RadioButtonList rblCCType
Credit Card Number TextBox txtCCNumber
Submit Button btnSubmit
Phone Number TextBox txtPhone

3. When the user clicks on the submit button, pgConfirm.aspx should be displayed. This is done with cross-page posting. To implement this, set the PostBackUrl property of the Submit button to ~/pgConfirm.aspx. This will cause the pgCheckOut.aspx to post user requests to the web page pgConfirm.aspx, which we will create shortly.

STEP C: Add Code to the pgCheckOut.aspx Form (to Read User Input and Implement Cross-page Posting)
Implement public methods in the pgCheckOut.aspx.cs code file to expose the form's control values to other pages. The code below is an example of how to retrieve the value of the txtFirstName and txtLastName.
Sample Method to Get Control Values
public TextBox FirstName
{ get { return txtFirstName; } }
public TextBox LastName
{ get { return txtLastName; } }

STEP D: Create and Design Another Web Form, pgConfirm.aspx
1. Add the second web form to your web application. Name the form pgConfirm.aspx.
2. Add label controls to display the user input values for the name, address, credit card type, and credit card number.
This allows the user to review and confirm order information before final submission. Add the controls in the table below to the form. The application will fill in the text displayed by the labels, so you don't need to. You should provide additional labels that describe these values for the user.
Control Type Control ID or Name Control Purpose
Label lblName Holds the concatenation string of first name and last name entered in pgChekout.aspx
Label lblAddress Holds the concatenation of all address-related fields user input in pgCheckOut.aspx
Label lblCCType Displays the credit card type the user selected in pgCheckOut.aspx
Label lblCCNumber Displays the credit card number the user entered in pgCheckOut.aspx
Label lblStatus Displays the message of any run time exception that might happen during run time
Button btnSubmit When the user clicks on the submit order button, this displays a note to the user that his or her order was submitted successfully. You should use the status label to display the message.

STEP E: Add Code to the pgConfirm.aspx Form (to Allow User to Verify Order Input and Submit for Final Processing)
1. In the pgConfirm.aspx page, add the following code to the PreviousPageType directive to the pgConfirm.aspx file, and set it to the pgCheckOut.aspx.
<%@ Page Language="C#" AutoEventWireup=“true" CodeFile="pgConfirm.aspx.cs" Inherits="pgConfirm" %>
<%@ PreviousPageType VirtualPath="~/pgCheckOut.aspx" %>
2. Next, in the Page_Load() event of the pgConfirm.aspx.cs code page, check whether there is any cross-page posting by checking whether there is a cross-page postback, and set the values of the label controls with the corresponding user input values from the previous page as shown below. Be sure to implement for all controls on the form.
3. Enclose your code in a try/catch block to handle any run time exception thrown by the application for any reason, as shown below.
4. Add code to have lblStatus display the message of any thrown exception. Don't forget to add comments explaining what each line of code does.
pgConfirm Page_Load method
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (PreviousPage.IsCrossPagePostBack)
{
lblName.Text = PreviousPage.FirstName.Text + " " + PreviousPage.LastName.Text;
// Your code to set other form labels goes here
}
}
catch (Exception error )
{
lblStatus.Text = error.Message;
}
}

STEP F: Compile, Test, Save, and Submit Your Project
1. Save your work!
2. Test it! Make changes as appropriate until it works.
3. Remember to add comments for each step being performed.
4. Please zip and submit the entire web project folder.

Product Tags

Use spaces to separate tags. Use single quotes (') for phrases.