ASP.

NET and Web Forms

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

JavaScript  Server-side technologies  ASP (Active Server Pages)  ASP.Web Development Technologies  Client-side technologies  HTML. DHTML.NET is the next generation of ASP Slide 4 of 72 .

Slide 5 of 72 .. Response. Application. . database connections. Session) provide services Commonly uses ADO to interact with databases Application and session variables Application and session begin/end events ASP manages threads..What is ASP?         ASP stands for Active Server Page Server-side programming technology Consists of static HTML interspersed with script ASP intrinsic objects (Request. Server.

XML ASP page (static HTML. HTTP header data) HTTP response HTML. server-side logic) Slide 6 of 72 .What is ASP? HTTP request (form data.

JScript – leverages existing skills  Script-based: no compiling.Reason for ASP Successes  Simple procedural programming model  Access to COM components    ActiveX Data Objects (ADO) File System Object Custom components VBScript. save & run   Support for multiple scripting languages  ASP has been very popular Slide 7 of 72 . just edit.

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 .NET Overview  ASP.NET provides services to allow the creation. and execution of Web Applications and Web Services  Like ASP.ASP. ASP. deployment.

ASP. easier to create and maintain Multiple. compiled languages Fast Scalable Manageable Available Customizable and extensible Secure Tool support Slide 9 of 72 .NET Overview Goals           Keep the good parts of ASP and improve the rest Simplify: less code.

ASP side by side Simplified form validation Cookieless sessions Slide 10 of 72 .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.

ASP.NET Architecture  ASP.NET is built upon   .NET Framework Internet Information Server (IIS) Slide 11 of 72 .

NET: Web Services and Web Forms Windows Forms ADO.ASP.NET Common Language Specification ASP.NET Architecture VB C++ C# JScript … Visual Studio.NET: Data and XML Base Classes Common Language Runtime Slide 12 of 72 .

Programming Model Controls and Events  Server-side programming model  Based on controls and events   Just like Visual Basic Not “data in. and maintainable Slide 13 of 72 . HTML out”  Higher level of abstraction than ASP  Requires less code  More modular. readable.

Programming Model Controls and Events Button Button code ... Text code . List code .... List Text Browser ASP..NET Event handlers Slide 14 of 72 .

ad rotator.Programming Model Server-side Controls  Multiple sources of controls    Built-in 3rd party User-defined  Controls range in complexity and power: button. text. validation  Can be populated via data binding Slide 15 of 72 . data grid. drop down. calendar.

Programming Model Automatic Browser Compatibility  Controls can provide automatic browser compatibility  Can target UpLevel or DownLevel browsers   UpLevel browsers support additional functionality.2 Slide 16 of 72 . such as JavaScript and DHTML DownLevel browsers support HTML 3.

WebForm1” %> Slide 17 of 72 .bas” Inherits=WebApplication1.NET pages   Controls and code in .aspx file.NET  Code-behind pages allow you to separate the user interface design from the code  Allows programmers and designers to work independently <%@ Codebehind=“WebForm1. code in code-behind page  Supported in Visual Studio.Programming Model Code-behind pages  Two styles of creating ASP.aspx file Controls in .

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  Works just like ASP: edit. save and run Slide 18 of 72 .Programming Model Automatic Compilation  Just edit the code and hit the page  ASP.

Programming Model Automatic Compilation Slide 19 of 72 .

--%> Render code: <%= %> and <% %>   Pages may contain:       Use is discouraged.aspx Directives: <%@ Page Language=“VB” %> Server controls: <asp:Button runat=“server”> Code blocks: <script runat=“server”>…</script> Data bind expressions: <%# %> Server side comments: <%-. use <script runat=server> with code in event handlers instead Slide 20 of 72 .Programming Basics Page Syntax  The most basic page is just static text  Any HTML page can be renamed .

NET class It names the instance available during postback Just like Dynamic HTML Slide 21 of 72  The id attribute provides programmatic identifier   .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” />  Tag identifies which type of control to create  Control is implemented as an ASP.

properties They become members of a custom Page object Slide 22 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>  Script blocks can contain   Variables. event handlers. methods.

Action Events Textbox1_Changed Button1_Click Page_Init Page_Load Save Control State Render Unload Page Page_Unload Slide 23 of 72 . Change Events 2.Programming Basics Page Event Lifecycle Initialize Restore Control State Load Page Control Events 1.

Programming Basics Page Loading  Page_Load fires at beginning of request after controls are initialized  Input control values already populated protected sub Page_Load(s as Object. World!" End sub Slide 24 of 72 .Text = "Howdy. e as EventArgs) message.

g. no applets. these execute only on next action event E.Programming Basics Server Control Events  Change Events    By default. OnClick No client script required. OnTextChanged.g. no ActiveX® Controls! Slide 25 of 72  Action Events    Works with any browser  . OnCheckedChanged Change events fire in random order Cause an immediate postback to server E.

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 .

HtmlControls.UI.bgcolor ="red"  Can specify client-side event handlers  Good when quickly converting existing pages  Derived from System. others derive from HtmlGenericControl Slide 27 of 72 .Web.Server Controls HTML Controls  Work well with existing HTML designers  Properties map 1:1 with HTML table.HtmlControl  Supported controls have custom class.

Server Controls HTML Controls  Supported controls         <a> <img> <form> <table> <tr> <td> <th> <select>         <textarea> <button> <input type=text> <input type=file> <input type=submit> <input type=button> <input type=reset> <input type=hidden> Slide 28 of 72 .

g. select lists)  Handle change events as well as action events Slide 29 of 72 .g. button click)  Event code will read the values of other controls (e.Server Controls HTML Controls  Can use controls two ways:  Handle everything in action events (e. radio buttons. text. check boxes.

Server Controls Web Controls  Four types of Web Controls     Intrinsic controls List controls Rich controls Validation controls Slide 30 of 72 .

Server Controls Intrinisic Controls  Correspond to HTML controls  Supported controls       <asp:button> <asp:imagebutton> <asp:linkbutton> <asp:hyperlink> <asp:textbox> <asp:checkbox>      <asp:radiobutton> <asp:image> <asp:label> <asp:panel> <asp:table> Slide 31 of 72 .

CheckBox and their subclasses don’t 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 Intrinisic Controls  TextBox. ListControl.

Server Controls List Controls  Controls that handle repetition  Supported controls        <asp:dropdownlist> <asp:listbox> <asp:radiobuttonlist> <asp:checkboxlist> <asp:repeater> <asp:datalist> <asp:datagrid> Slide 33 of 72 .

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  Server-side validation is always done  Slide 34 of 72 .

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>  . another control or data type Tests if value matches a predefined pattern Lets you create custom client.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.

Hashtable.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. DataReader XML Requires code to reapply to data model Slide 36 of 72  Supports binding to any data source      One way snapshot model  . DataTable. expressions. DataView. method calls Collections (Array.) DataSet. etc.

g. etc.  Enables the use of templates Slide 37 of 72 .DataBind binds all controls on a page  Works for scalars. DropDown control. the expression is evaluated and bound   DataBind for a single control (and subcontrols) Page. ListBox control.Data Binding What Is It?  Allows you to specify an expression  When the DataBind method of the control is called. e.g. Label control  Works for lists. e.

THE END THANK YOU VISHAL CHANDRA Slide 38 of 72 .

$07.439748 '.943.439748 #.439748 $/0 41 .../.07439748 0-439748 4:79508410-439748 39738.439748 89.

/4-:9943 .$07.-0 $/0 41 .853-:9943 .07439748 39738.855.439748 $:554790/.0 .859.-4 .852.85.0.-0 .439748 47708543/94%.857.0-:9943 .852.30 .85-:9943 .855073 .85.85909-4 .439748 .

..0398..$07.5489-.70.1:94!489./4.3/907 8:-.07439748 39738.4 .30 0...439748.8808/43 9..5489-.30/ $50. $/0 41 .9. 03907.:80..:942..0.97:0 942.439748 %094 8943974 0.

907 .$07.0.9.857050.-489 .857.07439748 89439748 4397489.8589-4 ./4-:994389 .3/070509943 $:554790/.85.9.85/.89 .439748 .7/ $/0 41 .9.85/.85/745/4389 .

3/807.07439748 '.7.943439748 #.$07.8/430 !70.07 :942..9.943 '.07 8/0./090.0398 ../.7../.0.././.43974 9038-0.039.94317.9..70/805.0398 $07.4/874:3/9758147:50.98:50..943/0.0398:807817428544130-4728 $/0 41 .90174235:9./.. /0.2047 $:554798.0./.9438.0.94343..

94307747834305.947 38:7089.708.2:2.34907.9.:08039070/ ..3/2././.85#06:70/0/'.:8942.950 .947 %08981.81.30'.947 0984:..08..39 .:0.:02.07 8/0..70.9431:3.7 85.85425.389..75708843'.947 0..943$:22.85:8942'.85#.943439748 .70'./..0 $/0 41 .4397447/.:0893232:2.9./.570/0130/5.07439748 '..4389..:08 ././.90.943 .9..88941./.85#0:.947 425.$07.99073 .039 47807.85'././.

84:7.9438 77.9. .#0./08.900-472.3805..-08.'0 .9..9.7.94 545:.584924/0 #06:708.4/09470.89.4/01742& $:554798-3/394.-0 09. .83082500954071:.4397489/.0 !74507908 057088438 2094/.3/3 .8 40.9. 3.0./07  30.24/0 $/0 41 .9.9.989 !74.$09 .94341.83.%.9.5594/.9.3/.-0 .

.0/ 900570884380.439748 !.-0 .0 .43974843.43974 478147898 0  74543 .0 4781478.305708843 0390.5.:..439748 .9.3/ 2094/4190..43974 .78 0  ..9.989 484:94850.9..3/ -3/8.-0890:80419025.1.90/.9.3/ 147.3/8:-..3/3 . 3.43974 09.830.908 $/0 41 .3/-4:3/ .43974  894 .

% % & '$# $/0 41 .

Sign up to vote on this title
UsefulNot useful