Professional Documents
Culture Documents
Training presentation
Objectives
What is ASP.NET ? why it was developed? ASP.NET features Programming Web Forms
Slide 2 of 72
Web Architecture
Client
Request: http://www.digimon.com/default.asp
PC/Mac/Unix/... + Browser
Network
HTTP, TCP/IP
Response: <html>.</html>
Server
Web Server
Slide 3 of 72
Server-side technologies
Slide 4 of 72
What is ASP?
ASP stands for Active Server Page Server-side programming technology Consists of static HTML interspersed with script ASP intrinsic objects (Request, Response, Server, Application, Session) provide services Commonly uses ADO to interact with databases Application and session variables Application and session begin/end events ASP manages threads, database connections, ...
Slide 5 of 72
What is ASP?
HTTP request
(form data, HTTP header data)
HTTP response
HTML, XML
ASP page
(static HTML, server-side logic)
Slide 6 of 72
Reason for
ASP Successes
Simple procedural programming model Access to COM components
ActiveX Data Objects (ADO) File System Object Custom components VBScript, JScript leverages existing skills
Support for multiple scripting languages ASP has been very popular
Slide 7 of 72
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
Slide 8 of 72
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
Slide 9 of 72
ASP.NET Overview
Key Features
Web Forms Web Services Built on .NET Framework Simple programming model Maintains page state Multibrowser support XCOPY deployment XML configuration Complete object model
Session management Caching Debugging Extensibility Separation of code and UI Security ASPX, ASP side by side Simplified form validation Cookieless sessions
Slide 10 of 72
ASP.NET
Architecture
ASP.NET is built upon
Slide 11 of 72
ASP.NET
Architecture
VB C++ C# JScript
Visual Studio.NET
Common Language Specification ASP.NET: Web Services and Web Forms Windows Forms
Slide 12 of 72
Programming Model
Controls and Events
Server-side programming model Based on controls and events
Higher level of abstraction than ASP Requires less code More modular, readable, and maintainable
Slide 13 of 72
Programming Model
Controls and Events
Button
List
Text
Browser
ASP.NET
Event handlers
Slide 14 of 72
Programming Model
Server-side Controls
Multiple sources of controls
Controls range in complexity and power: button, text, drop down, calendar, data grid, ad rotator, validation Can be populated via data binding
Slide 15 of 72
Programming Model
Automatic Browser Compatibility
Controls can provide automatic browser compatibility Can target UpLevel or DownLevel browsers
UpLevel browsers support additional functionality, such as JavaScript and DHTML DownLevel browsers support HTML 3.2
Slide 16 of 72
Programming Model
Code-behind pages
Two styles of creating ASP.NET pages
Controls and code in .aspx file Controls in .aspx file, code in code-behind page
Code-behind pages allow you to separate the user interface design from the code
Programming Model
Automatic Compilation
Just edit the code and hit the page ASP.NET will automatically compile the code into an assembly Compiled code is cached in the CLR Assembly Cache Subsequent page hits use compiled assembly If the text of the page changes then the code is recompiled
Programming Model
Automatic Compilation
Slide 19 of 72
Programming Basics
Page Syntax
The most basic page is just static text
Any HTML page can be renamed .aspx Directives: <%@ Page Language=VB %> Server controls: <asp:Button runat=server> Code blocks: <script runat=server></script> Data bind expressions: <%# %> Server side comments: <%-- --%> Render code: <%= %> and <% %>
Use is discouraged; use <script runat=server> with code in event handlers instead
Slide 20 of 72
Programming Basics
Server Control Syntax
Controls are declared as HTML tags with runat=server attribute
<input type=text id=text2 runat=server /> <asp:calendar id= myCal runat=server />
Control is implemented as an ASP.NET class It names the instance available during postback Just like Dynamic HTML
Slide 21 of 72
Programming Basics
Server Code Blocks
Server code lives in a script block marked runat=server
<script language="C#" runat=server> <script language="VB" runat=server> <script language="JScript" runat=server>
Variables, methods, event handlers, properties They become members of a custom Page object
Slide 22 of 72
Programming Basics
Page Event Lifecycle
Initialize Restore Control State Load Page Control Events
1. Change Events 2. Action Events Textbox1_Changed Button1_Click Page_Init Page_Load
Page_Unload
Slide 23 of 72
Programming Basics
Page Loading
Page_Load fires at beginning of request after controls are initialized
protected sub Page_Load(s as Object, e as EventArgs) message.Text = "Howdy, World!" End sub
Slide 24 of 72
Programming Basics
Server Control Events
Change Events
By default, these execute only on next action event E.g. OnTextChanged, OnCheckedChanged Change events fire in random order Cause an immediate postback to server E.g. OnClick No client script required, no applets, no ActiveX Controls!
Slide 25 of 72
Action Events
Server Controls
ASP.NET ships with ~50 built-in controls Organized into logical families
HTML controls
Controls / properties map 1:1 with HTML Richer functionality More consistent object model
Web controls
Slide 26 of 72
Server Controls
HTML Controls
Work well with existing HTML designers Properties map 1:1 with HTML
table.bgcolor ="red"
Can specify client-side event handlers Good when quickly converting existing pages Derived from
System.Web.UI.HtmlControls.HtmlControl
Server Controls
HTML Controls
Supported controls
<textarea> <button> <input type=text> <input type=file> <input type=submit> <input type=button> <input type=reset> <input type=hidden>
Slide 28 of 72
Server Controls
HTML Controls
Can use controls two ways:
Event code will read the values of other controls (e.g. text, check boxes, radio buttons, select lists)
Slide 29 of 72
Server Controls
Web Controls
Four types of Web Controls
Slide 30 of 72
Server Controls
Intrinisic Controls
Correspond to HTML controls Supported controls
Slide 31 of 72
Server Controls
Intrinisic Controls
TextBox, ListControl, CheckBox and their subclasses dont automatically do a postback when their controls are changed Specify AutoPostBack=true to make change events cause a postback
Slide 32 of 72
Server Controls
List Controls
Controls that handle repetition Supported controls
Server Controls
Validation Controls
Rich, declarative validation Validation declared separately from input control Extensible validation framework Supports validation on client and server
Automatically detects uplevel clients Avoids roundtrips for uplevel clients Prevents users from spoofing Web Forms
Slide 34 of 72
Server Controls
Validation Controls
<asp:RequiredFieldValidator>
Ensures that a value is entered Checks if value is within minimum and maximum values Compares value against constant, another control or data type Tests if value matches a predefined pattern Lets you create custom client- or server-side validation function Displays list of validation errors in one place
Slide 35 of 72
<asp:RangeValidator>
<asp:CompareValidator>
<asp:RegularExpressionValidator>
<asp:CustomValidator>
<asp:ValidationSummary>
Data Binding
What Is It?
Provides a single simple yet powerful way to populate Web Form controls with data
Enables clean separation of code from UI Properties, expressions, method calls Collections (Array, Hashtable, etc.) DataSet, DataTable, DataView, DataReader XML Requires code to reapply to data model
Slide 36 of 72
Data Binding
What Is It?
Allows you to specify an expression When the DataBind method of the control is called, the expression is evaluated and bound
DataBind for a single control (and subcontrols) Page.DataBind binds all controls on a page
Works for scalars, e.g. Label control Works for lists, e.g. DropDown control, ListBox control, etc. Enables the use of templates
Slide 37 of 72
THE END
THANK YOU
VISHAL CHANDRA
Slide 38 of 72