Transcription
Chapter 1An introduction toASP.NET programmingMurach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 1
The components of a web application ComputerThe InternetWeb ServerTabletSmart PhoneMurach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 2
A static web pageMurach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 3
How a web server processes a static web pageMurach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 4
A dynamic web pageMurach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 5
How a web server processes a dynamic web pageHTTP request Web BrowserMurach's ASP.NET 4.5/C#, C1HTTP response(with HTML)Web Server(IIS)Application Server(ASP.NET) 2013, Mike Murach & Associates, Inc.Database ServerSlide 6
The two main ASP.NET technologies ASP.NET Web Forms ASP.NET MVCThree other ASP.NET technologies ASP.NET Web Pages with Razor ASP.NET Dynamic Data Entities ASP.NET Reports Web SiteMurach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 7
The four editions of Visual Studio 2012 Visual Studio Express 2012 for Web Visual Studio Professional 2012 Visual Studio Premium 2012 Visual Studio Ultimate 2012The free edition of Visual Studio for web apps Visual Studio 2012 Express for WebWhat the free edition includes IIS Express SQL Server Express LocalDBMurach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 8
Standalone developmentWhat you need on your PC Windows 7 or later .NET Framework 4.5 Visual Studio 2012 IIS Express SQL Server Express LocalDBMurach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 9
Why state is difficult to track in a web applicationClientBrowserBrowserBrowserMurach's ASP.NET 4.5/C#, C1ServerFirst HTTP request:The browser requests a page.First HTTP response:The server returns therequested page and theapplication ends.Next HTTP request:The browser requests anotherpage. The server has no wayto associate the browser withits previous request. 2013, Mike Murach & Associates, Inc.Web serverWeb serverWeb serverSlide 10
Five ASP.NET features for maintaining state View state (chapter 2 and 8) Session state (chapter 4 and 8) Application state (chapter 8) Server-side caching (chapter 8) ProfilesMurach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 11
The Future Value applicationafter the user clicks the Calculate buttonMurach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 12
The Future Value applicationwith error messages displayedMurach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 13
The Future Value form in Design viewof Visual Studio 2012Murach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 14
The files in the Future Value applicationFolder(root)(root)(root)ImagesMurach's ASP.NET 4.5/C#, ogo.jpg 2013, Mike Murach & Associates, Inc.Slide 15
The aspx file for the Default form (Default.aspx) %@ Page Language "C#" AutoEventWireup "true" CodeFile "Default.aspx.cs"Inherits " Default" % !DOCTYPE html html xmlns "http://www.w3.org/1999/xhtml" head id "Head1" runat "server" title Chapter 1: Future Value /title style !-- 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 style "color: #0000FF" 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 tr td class "style3" Annual interest rate /td td asp:TextBox ID "txtInterestRate" runat "server"Width "100px" 6.0 /asp:TextBox /td /tr tr td class "style3" Number of years /td Murach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 16
The aspx file for the Default form (cont.) 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" /td td /td /tr 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 Murach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 17
The code-behind file for the Default ublic partial class Default : System.Web.UI.Page{protected void Page Load(object sender, EventArgs e){if (!IsPostBack)for (int i 50; i 500; i urach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 18
The code-behind file for the Default form (cont.)protected void btnCalculate Click(object sender, EventArgs e){if (IsValid){int monthlyInvestment );decimal yearlyInterestRate Convert.ToDecimal(txtInterestRate.Text);int years Convert.ToInt32(txtYears.Text);decimal futureValue this.CalculateFutureValue(monthlyInvestment, yearlyInterestRate, years);lblFutureValue.Text futureValue.ToString("c");}}Murach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 19
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 "";}}Murach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc.Slide 20
Murach's ASP.NET 4.5/C#, C1 2013, Mike Murach & Associates, Inc. Slide 2 The components of a web application