Module 1: Working with ASP.NET
Overview
Introducing ASP.NET
Creating Web Forms
Adding ASP.NET Code to a Page
Handling Page Events
Discussion: ASP vs. ASP.NET
Introducing ASP.NET
The .NET Framework
ASP.NET Features
Animation: The ASP.NET Execution Model
The .NET Framework
.NET.NETFramework Framework
.NET.NETFramework Framework
InternetInternetInternetInternet
COM+COM+COM+COM+
OrchestrationOrchestration OrchestrationOrchestration
Windows Windows
.NET Enterprise
Servers
.NET Enterprise
Servers
BuildingBuildingBlockBlock
ServicesServices
BuildingBuildingBlockBlock
ServicesServices
Visual Studio.NET Visual Studio.NET
Base Class LibraryBase Class Library
ADO.NET: Data & XMLADO.NET: Data & XML
UserUserInterfaceInterface
Common Language RuntimeCommon Language Runtime
WebWebServicesServices
ASP.NET Features
Multiple Language Support
Increased Performance
Compiled code
Cache
Classes and Namespaces
Server Controls
Web Services
ASP.NET Features (continued)
Improved Security
Greater Scalability
Cookie-less Sessions
Easy Configuration and Deployment
Animation: The ASP.NET Execution Model
Creating Web Forms
What Are Web Forms?
What Are Server Controls?
Types of Server Controls
How Do Server Controls Work?
Demonstration: Adding Server Controls to an ASP.NET Page
What Are Web Forms?
.aspx extension
@Page Directive
Framework Is an Object Model
Denoted by the runat="server" Attribute
Contain Client-side and Server-side Code
Contain HTML and Server Controls
<Form runat="server"></Form>
<Form runat="server"></Form>
<%@ Page Language=“C#" %> <%@ Page Language=“C#" %>
What Are Server Controls?
Server-programmable Objects
Denoted by Tag with the runat = "server" Attribute
Encapsulate Both Behavior and Rendering
Fully Declarative
Render Different HTML to Support Multiple Browsers or other Web Clients
Types of Server Controls
HTML Controls
Exist within the System.Web.UI.HtmlControls namespace
Web Controls
Exist within the System.Web.UI.WebControls namespace
<input type="text" id="txtName" runat="server"><span id="spnStarter" runat="server">starter</span>
<input type="text" id="txtName" runat="server"><span id="spnStarter" runat="server">starter</span>
<asp:TextBox id="txtName" runat="server"Text="[Entry Keywords]"/>
<asp:TextBox id="txtName" runat="server"Text="[Entry Keywords]"/>
How Do Server Controls Work?
Declared with runat="server" Attribute
When the ASP.NET Page is Executed:
Creates action and method attributes of form
Adds unique id and name attributes to controls
Adds value attribute to controls
Adds a hidden control to the form to save view state information
<input type="text" id="text2" runat="server"><input type="text" id="text2" runat="server">
Demonstration: Adding Server Controls to an ASP.NET Page
Adding ASP.NET Code to a Page
Creating ASP.NET <SCRIPT> Section
Creating Event Procedures
Demonstration: Adding Code to Controls
Creating ASP.NET <SCRIPT> Section
Declaring the Language
Declaring Functions and Subroutines
<script language="VB" runat="server"><script language="C#" runat="server">
<script language="VB" runat="server"><script language="C#" runat="server">
<SCRIPT LANGUAGE="VB" runat="server"> Sub login () 'contents of routine End Sub</SCRIPT>
<SCRIPT LANGUAGE="VB" runat="server"> Sub login () 'contents of routine End Sub</SCRIPT>
Creating Event Procedures
Assign a Method Name to the Event Attribute
Create an Event Procedure in Your Page Code
Access Properties of Controls in the Event Procedure
<input type="submit" value="Submit!" onServerClick="GreetMe" runat="server">
<input type="submit" value="Submit!" onServerClick="GreetMe" runat="server">
Sub GreetMe(s As Object, e As EventArgs) Sub GreetMe(s As Object, e As EventArgs)
Sub GreetMe(s As Object, e As EventArgs) spnGreeting.InnerHTML = "Hello " & _
txtName.ValueEnd Sub
Sub GreetMe(s As Object, e As EventArgs) spnGreeting.InnerHTML = "Hello " & _
txtName.ValueEnd Sub
Demonstration: Adding Code to Controls
Handling Page Events
Page Event Life Cycle
Handling Postback Forms
Demonstration: Using Postback Forms
Page Event Life Cycle
Page_LoadPage_Load
Page_UnloadPage_Unload
Textbox1_ChangedTextbox1_Changed
Button1_ClickButton1_Click
Page is disposed
Page_InitPage_Init
Handling Postback Forms
ViewState Control Maintains the State of a Page During Postback
Page_Load Fires on Every Request
Use Page.IsPostBack to execute conditional logic
Sub Page_Load(s As Object, e As EventArgs) If Not Page.IsPostBack Then 'executes only on initial page load End If 'Rest of procedure executes on every requestEnd Sub
Sub Page_Load(s As Object, e As EventArgs) If Not Page.IsPostBack Then 'executes only on initial page load End If 'Rest of procedure executes on every requestEnd Sub
Demonstration: Using Postback Forms
Discussion: ASP vs. ASP.NET
Lab 1: Using ASP.NET to Output Text
Review
Introducing ASP.NET
Creating Web Forms
Adding ASP.NET Code to a Page
Handling Page Events
Discussion: ASP vs. ASP.NET