Web Technologies ASP.NET Intro : Web Technologies ASP.NET Intro
Learning Objectives : Learning Objectives ASP.NET
Agenda : Agenda ASP.NET Overview
ASP.NET Programming Model
ASP.NET Programming Basics
Agenda : Agenda ASP.NET Overview
Programming Model
Programming Basics
BackgroundWeb Architecture : BackgroundWeb Architecture Web Server PC/Mac/Unix/... + Browser Client Server Request:
http://www.digimon.com/default.asp Response:
…. Network HTTP, TCP/IP
ASP.NET Overview : 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 web-based applications as easy as building Visual Basic applications
Web Form = Visual Drag and Drop tools
ASP.NET OverviewGoals : ASP.NET OverviewGoals Simple: less code, easier to create and maintain
Multiple, compiled languages
Fast
Scalable
Manageable
Customizable and extensible
Secure
Tool support (Visual Studio.NET)
ASP.NET OverviewKey Features : ASP.NET OverviewKey Features Web Forms
Web Services
Built on .NET Framework
Simple programming model
Maintains page state
Multi-browser support
Complete object model Session management
Caching
Debugging
Separation of code and UI
Security
ASPX, ASP side by side
Simplified form validation
Cookieless sessions
ASP.NET OverviewArchitecture : ASP.NET OverviewArchitecture
Agenda : Agenda ASP.NET Overview
Programming Model
Programming Basics
Programming ModelControls and Events : Programming ModelControls and Events Server-side programming model
Based on controls and events, not “data in, HTML out”
Requires less code
More modular, readable, and maintainable
Programming ModelControls and Events : Programming ModelControls and Events Browser ASP.NET Button code
... List code
... Text code
... Event handlers
Programming ModelASP.NET Object Model : Programming ModelASP.NET Object Model Controls are objects, available in server-side code
Derived from System.Web.UI.Control
The web page is an object too
Derived from System.Web.UI.Page
User code executes on the web server in page or control event handlers
Programming ModelPostbacks : Programming ModelPostbacks A postback occurs when a page generates an HTML form whose values are posted back to the same page
A common technique for handling form data
In ASP and other server-side technologies the state of the page is lost upon postback...
Unless you explicitly write code to maintain state
This is tedious, bulky and error-prone
Programming ModelPostbacks Maintain State : Programming ModelPostbacks Maintain State By default, ASP.NET maintains the state of all server-side controls during a postback
Must use method="post“ (in the HTML Form, method=“get”)
Server-side control objects are automatically populated during postback
No state stored on server
Works with all browsers
Programming ModelServer-side Controls : Programming ModelServer-side Controls Multiple sources of controls
Built-in (~ 50 built in!)
3rd party
User-defined
Controls range in complexity and power: button, text, drop down, calendar, data grid, ad rotator, validation
Can be populated via data binding (which we will discuss in depth next week)
Programming ModelAutomatic Browser Compatibility : Programming ModelAutomatic Browser Compatibility Controls can provide automatic browser compatibility
Can target UpLevel or DownLevel browsers
UpLevel browsers support additional functionality, such as JavaScript
DownLevel browsers support HTML 3.2
Programming ModelAutomatic Browser Compatibility : Programming ModelAutomatic Browser Compatibility Button code
... Menu code
... Text code
... Event handlers ASP.NET Button Control Menu Control Text Control ...
Programming ModelCode-behind pages : Programming ModelCode-behind pages Two styles of creating ASP.NET pages
Controls and code in .aspx file
Controls in .aspx file, code in code-behind page
Supported in Visual Studio.NET
Code-behind pages allow you to separate the user interface design from the code
Allows programmers and designers to work independently <%@ Codebehind=“WebForm1.cs”
Inherits=WebApplication1.WebForm1” %>
Programming ModelAutomatic Compilation : Programming ModelAutomatic 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 Subsequent page hits use compiled assembly
If the text of the page changes then the code is recompiled
Works just like ASP: edit, save and run
Programming ModelAutomatic Compilation : Programming ModelAutomatic Compilation
Agenda : Agenda ASP.NET Overview
Programming Model
Programming Basics
Programming BasicsPage Syntax : Programming BasicsPage Syntax The most basic page is just static text
Any HTML page can be renamed .aspx
Pages may contain:
Directives: <%@ Page Language=“C#” %>
Server controls:
Code blocks:
Data bind expressions: <%# %>
Server side comments: <%-- --%>
Programming BasicsServer Control Syntax : Programming BasicsServer Control Syntax Controls are declared as HTML tags with runat=“server” attribute
Tag identifies which type of control to create
Control is implemented as an ASP.NET class
The id attribute provides programmatic identifier
It names the instance available during postback
Just like Dynamic HTML
Programming BasicsServer Control Properties : Programming BasicsServer Control Properties Tag attributes map to control properties c1.Text = “Foo”;
c2.Rows = 5;
Tags and attributes are case insensitive
Control properties can be set programmatically
Programming BasicsMaintaining State : Programming BasicsMaintaining State By default. controls maintain their state across multiple postback requests
Implemented using a hidden HTML field: __VIEWSTATE
Works for controls with input data (e.g. TextBox, CheckBox), non-input controls (e.g. Label, DataGrid), and hybrids (e.g. DropDownList, ListBox)
Can be disabled per control or entire page
Set EnableViewState=“false”
Programming BasicsServer Code Blocks : Programming BasicsServer Code Blocks Server code lives in a script block marked runat=“server”
Script blocks can contain
Variables, methods, event handlers, properties
They become members of a custom Page object