Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 30

Chapter 1

An introduction to
ASP.NET programming

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 1
Objectives
Knowledge
1. Describe the components of a web application.
2. Describe the four components of a URL, and describe what happens
when you omit the file name from a URL when you request a web
page.
3. Distinguish between static and dynamic web pages, with the focus
on the web server, application server, and database server.
4. Distinguish between the Internet and an intranet.
5. Describe these terms: HTTP request, HTTP response, and round trip.
6. Distinguish between ASP.NET Web Forms applications and MVC
applications.
7. Describe the three types of environments that can be used for
developing ASP.NET applications.

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 2
Objectives (continued)
8. List the software components that you need on your own PC if you
want to develop and run ASP.NET web applications in a standalone
environment, including database applications.
9. Describe the class libraries and Common Language Runtime of the
.NET Framework.
10. Distinguish between the aspx files and the code-behind files in an
ASP.NET web application.

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 3
The Order page of a Shopping Cart application

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 4
The Cart page of a Shopping Cart application

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 5
The components of a web application

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 6
The components of an HTTP URL

http://www.modulemedia.com/ourwork/index.html
protocol domain name path file name

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 7
A static web page

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 8
How a web server processes a static web page

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 9
A dynamic web page

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 10
How a web server processes
a dynamic web page

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 11
The two main ASP.NET technologies
 ASP.NET Web Forms
 ASP.NET MVC

The differences between the technologies


Technology Description
ASP.NET Web Forms A development environment similar to
Windows Forms, with controls on a
design surface. Its focus is on Rapid
Application Development (RAD).
ASP.NET MVC A development environment similar to
PHP or classic ASP. It uses the Model-
View-Controller (MVC) design pattern
and the Razor templating engine for in-
line data binding.

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 12
The two main types
of ASP.NET Web Forms projects
 Web application projects
 Web site projects

The differences between the project types


Project type Description
Web appliction A project file stores information about the
application, and the application files are
compiled into a single assembly. This
assembly is then deployed to the web server.
Web site There is no project file. Rather, all the files
that are in the root directory are included in
the web site. The files are individually
deployed to the web server, and the site is
dynamically compiled the first time the web
site is requested.

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 13
Standalone development

What you need on your PC


 Windows 7 or later
 .NET Framework 4.6
 Visual Studio 2015
 IIS Express
 SQL Server Express LocalDB

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 14
Intranet development

What you need on your PC


 Windows 7 or later
 .NET Framework 4.6
 Visual Studio 2015

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 15
Internet development

What you need on your PC


 Windows 7 or later
 .NET Framework 4.6
 Visual Studio 2015

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 16
The three editions of Visual Studio 2015
Edition Description
Visual Studio Community 2015 Free edition for Windows, web,
and mobile apps.
Visual Studio Professional 2015 For individuals or small teams,
it includes basic tools for
testing, database deployment,
and change and lifecycle
management.
Visual Studio Enterprise 2015 For teams, it includes full
testing, modeling, database, and
lifecycle management tools.

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 17
The .NET Framework

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 18
Why state is difficult to track
in a web application

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 19
Five ASP.NET features for maintaining state
 View state (chapters 2 and 8)
 Session state (chapters 4 and 8)
 Application state (chapter 8)
 Server-side caching (chapter 8)
 Individual user accounts (chapter 20)

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 20
The Future Value application
after the user clicks the Calculate button

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 21
The Future Value application
with error messages displayed

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 22
The Future Value form in Design view
of Visual Studio 2015

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 23
Some of the files in the Future Value application
Folder File Description
(root) Default.aspx The aspx file for the
default page.
(root) Default.aspx.cs The code-behind file
for the default page.
(root) Default.aspx.designer.cs The generated code for
the default page.
(root) Web.config XML files that contain
packages.config
configuration data.
Images MurachLogo.jpg The logo image for the
form.

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 24
The aspx file for the Default form (Default.aspx)
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="Ch01FutureValue.Default" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Chapter 1: Future Value</title>
<style type="text/css">
<!-- CSS code for the generated styles -->
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<img alt="Murach" class="style1"
src="Images/MurachLogo.jpg" /><br />
<h1>401K Future Value Calculator</h1>
<table class="style2">
<tr>
<td class="style3">Monthly investment</td>
<td><asp:DropDownList ID="ddlMonthlyInvestment"
runat="server" Width="106px">
</asp:DropDownList></td>
</tr>

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 25
The aspx file for the Default form (cont.)
<tr>
<td class="style3">Annual interest rate</td>
<td><asp:TextBox ID="txtInterestRate" runat="server"
Width="100px">3.0</asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">Number of years</td>
<td><asp:TextBox ID="txtYears" runat="server"
Width="100px">10</asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">Future value</td>
<td><asp:Label ID="lblFutureValue" runat="server"
Font-Bold="True"></asp:Label>
</td>
</tr>
<tr>
<td class="style3">&nbsp;</td>
<td>&nbsp;</td>
</tr>

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 26
The aspx file for the Default form (cont..)
<tr>
<td class="style3"><asp:Button ID="btnCalculate"
runat="server" Text="Calculate" Width="100px"
OnClick="btnCalculate_Click" /></td>
<td><asp:Button ID="btnClear" runat="server"
Text="Clear" Width="100px"
OnClick="btnClear_Click"
CausesValidation="False" />
</td>
</tr>
</table>
<br />
<!-- aspx code for the field validators -->
</div>
</form>
</body>
</html>

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 27
The code-behind file for the Default form
(Default.aspx.cs)
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
// the rest of the default using directives

namespace Ch01FutureValue
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
for (int i = 50; i <= 500; i += 50)
ddlMonthlyInvestment.Items.Add(i.ToString());
}

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 28
The code-behind file for the Default form (cont.)
protected void btnCalculate_Click(object sender,
EventArgs e)
{
if (IsValid) {
int monthlyInvestment =
Convert.ToInt32(
ddlMonthlyInvestment.SelectedValue);
decimal yearlyInterestRate =
Convert.ToDecimal(txtInterestRate.Text);
int years = Convert.ToInt32(txtYears.Text);
decimal futureValue = this.CalculateFutureValue(
monthlyInvestment, yearlyInterestRate, years);
lblFutureValue.Text = futureValue.ToString("c");
}
}

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 29
The code-behind file for the Default form (cont..)
protected decimal CalculateFutureValue(
int monthlyInvestment, decimal yearlyInterestRate,
int years)
{
int months = years * 12;
decimal monthlyInterestRate =
yearlyInterestRate / 12 / 100;
decimal futureValue = 0;
for (int i = 0; i < months; i++)
{
futureValue = (futureValue + monthlyInvestment)
* (1 + monthlyInterestRate);
}
return futureValue;
}
protected void btnClear_Click(object sender, EventArgs e)
{
ddlMonthlyInvestment.SelectedIndex = 0;
txtInterestRate.Text = "";
txtYears.Text = "";
lblFutureValue.Text = "";
}
} // end class
} // end namespace

© 2016, Mike Murach & Associates, Inc.


Murach's ASP.NET 4.6 with C# 2015 C1, Slide 30

You might also like