And Web Forms: Outline
And Web Forms: Outline
NET
and Web Forms
This material is based on the original slides of Dr. Mark Sapossnek, Computer Science Department,
Boston University, Mosh Teitelbaum, evoch, LLC, and Joe Hummel, Lake Forest College
Outline
Background
ASP.NET Overview
Programming Model
Programming Basics
Server Controls
Data Binding
Conclusion
Background
Web Architecture
PC/Mac/Unix/...
Client
+ Browser
Request:
http://www.digimon.com/default.asp
Response:
<html>….</html>
Background
Web Development Technologies
Client-side technologies
XHTML, CSS, DOM, JavaScript
Server-side technologies
ASP (Active Server Pages)
ASP.NET is the next generation of ASP
Background
What is ASP?
Background
What is ASP?
ASP page
(static HTML,
server-side logic)
Background
Example: HelloWorld.asp
<html>
<head><title>HelloWorld.asp</title></head>
<body>
<form method=“post">
<input type="submit" id=button1 name=button1
value="Push Me" />
<%
if (Request.Form("button1") <> "") then
Response.Write "<p>Hello, the time is " & Now()
end if
%>
</form>
</body>
</html>
Background
ASP Challenges
Coding overhead (too much code)
Everything requires writing code!
Code readability (too complex; code and UI intermingled)
Maintaining page state [After submit button is clicked, if
we click the back button, we expect to maintain scroll
position, maintain which control had focus, and restore
focus, or allow server code to focus a new control ]
requires more code
Session state scalability and availability
Limited support for caching, tracing, debugging, etc.
Performance and safety limitations of script
Outline
Background
ASP.NET Overview
Programming Model
Programming Basics
Server Controls
Data Binding
Conclusion
ASP.NET Overview
ASP.NET provides services to allow the
creation, deployment, and execution of
Web Applications and Web Services
Like ASP, ASP.NET is a server-side technology
Web Applications are built using Web Forms
Web Forms are designed to make building
web-based applications as easy as building
Visual Basic applications
ASP.NET Overview
Goals
Keep the good parts of ASP and improve the rest
Simplify: less code, easier to create and maintain
Multiple, compiled languages
Fast
Scalable
Manageable
Available
Customizable and extensible
Secure
Tool support
ASP.NET Overview
Key Features
ASP.NET Overview
Architecture
ASP.NET Overview
Architecture
VB C++ C# JScript …
Visual Studio.NET
Base Classes
Programming Model
Controls and Events
Button code
Button ...
List code
List ...
Text code
Text ...
Programming Model
ASP.NET Object Model
Programming Model
Postbacks Maintain State
Programming Model
Automatic Browser Compatibility
Menu
Text
Text
Menu Control Menu code
...
IE 5.5
Button
Text Control Text code
Menu
Text
...
IE 6
Button
...
Programming Model
Code-behind pages
Programming Model
Automatic Compilation
Outline
Background
ASP.NET Overview
Programming Model
Programming Basics
Server Controls
Data Binding
Conclusion
Programming Basics
Page Syntax
Programming Basics
Server Control Syntax
Programming Basics
Maintaining State
Example: MaintainingState.aspx
Programming Basics
Server Code Blocks
Programming Basics
Page Event Lifecycle
Initialize Page_Init
Restore Control State
Load Page Page_Load
Control Events
1. Change Events Textbox1_Changed
Programming Basics
Page Loading
Change Events
By default, these execute only on next action event
E.g. OnTextChanged, OnCheckedChanged
Change events fire in random order
Action Events
Cause an immediate postback to server
E.g. OnClick
Works with any browser
No client script required, no applets,
no ActiveX® Controls!
Programming Basics
Wiring Up Control Events
Programming Basics
Page Unloading
Programming Basics
Page Class
Server Controls
ASP.NET ships with ~50 built-in controls
Organized into logical families
HTML controls
z Controls / properties map 1:1 with HTML
Web controls
z Richer functionality
z More consistent object model
Server Controls
HTML Controls
Server Controls
HTML Controls
Supported controls
<a> <textarea>
<img> <button>
<form> <input type=text>
<table> <input type=file>
<tr> <input type=submit>
<td> <input type=button>
<th> <input type=reset>
<select> <input type=hidden>
Server Controls
HTML Controls
Example: HTMLControls.aspx
Basic page lifecycle with HTML Controls
Server Controls
Web Controls
Richer functionality
E.g. AutoPostBack, additional methods
Automatic uplevel/downlevel support
E.g. validation controls
Strongly-typed; no generic control
Enables better compiler type checking
Server Controls
Web Controls
Server Controls
Web Controls
Server Controls
Intrinisic Controls
Correspond to HTML controls
Supported controls
<asp:button>
<asp:radiobutton>
<asp:imagebutton>
<asp:linkbutton> <asp:image>
<asp:hyperlink> <asp:label>
<asp:textbox> <asp:panel>
<asp:checkbox> <asp:table>
Server Controls
CheckBoxList & RadioButtonList
Example: WebControls.aspx
Assorted intrinsic and list controls with
AutoPostBack
Server Controls
Rich Controls
Server Controls
Validation Controls
<asp:RequiredFieldValidator>
Ensures that a value is entered
<asp:RangeValidator>
Checks if value is within minimum and maximum values
<asp:CompareValidator>
Compares value against constant, another control or data type
<asp:RegularExpressionValidator>
Tests if value matches a predefined pattern
<asp:CustomValidator>
Lets you create custom client- or server-side validation function
<asp:ValidationSummary>
Displays list of validation errors in one place
Server Controls
Validation Controls
Server Controls
Validation Controls
<asp:RequiredFieldValidator id="Req1"
ControlToValidate="TextBox1"
Text="Required Field" runat=server />
Server Controls
Validation Controls
Server Controls
Validation Controls
Example: ValidationControls.aspx