Date post: | 10-Apr-2018 |
Category: |
Documents |
Upload: | ryan-nguyen |
View: | 222 times |
Download: | 0 times |
of 30
8/8/2019 Session 3 TP2
1/30
Session 3
Objects in ASP.NET
8/8/2019 Session 3 TP2
2/30
Exploring ASP.NET / Session 3 / 2 of 30
Review Active Server Pages (ASP) is a server-side scripting environment that
provides a web server with the capability to process applicationlogic, and return standard HTMLpages to the browser.
Web Forms provides a form designer, an editor and debugging tools,which can be used to rapidly build server-based, programmable userinterfaces for browsers and Web client devices.
The Design view displays the page layout of the web page as itwould be displayed in the browser.
The HTML view displays the code that is automatically generated tocreate the Web page.
AssemblyInfo.cs is the file that contains information about theproject. It contains information such as name, version, and cultureinformation.
Once the code has been compiled, the CLR further compiles the IL tonative code, when the request for the web page is encountered,providing improved performance.
8/8/2019 Session 3 TP2
3/30
Exploring ASP.NET / Session 3 / 3 of 30
Review Contd Web.config is an XML based file. It holds unique configuration
information about each URL used in the project. Global.asax is an optional file that is used for handling application-
level events. The web page created either using the editor or Web Forms, is first
complied to Intermediate Language (IL), including server scripts. The different web pages of an application created using Web Forms,
and the program code within it, are compiled into a single assembly /dynamic link library (.dll) file.
In the editor based web application, separate dynamic link libraries(.dll's) are created for each file. The web pages created using Web Forms, will have the Codebehind
attribute that informs Web Forms IDE about the code file that has tobe changed whenever a change is made to the Design, or the HTMLview of the Web Form.
8/8/2019 Session 3 TP2
4/30
Exploring ASP.NET / Session 3 / 4 of 30
Objectives Explain the basics of ASP.NET
Discuss the process flow ofa .aspxpage
Explain the Page_Loadevent
Discuss the IsPostBack propertyof
the Page object Use the Request andResponse
Objects
8/8/2019 Session 3 TP2
5/30
Exploring ASP.NET / Session 3 / 5 of 30
An ASP.NET Page
Page Directive
section
Page_Load Event
Event Handler
HTML Control
Web Control
8/8/2019 Session 3 TP2
6/30
Exploring ASP.NET / Session 3 / 6 of 30
An ASP.NET Page - Output
Output after the Page
Load Event
Output after the Button
Click Event
8/8/2019 Session 3 TP2
7/30
Exploring ASP.NET / Session 3 / 7 of 30
Starting with ASP.NET
8/8/2019 Session 3 TP2
8/30
Exploring ASP.NET / Session 3 / 8 of 30
User Interface
8/8/2019 Session 3 TP2
9/30
8/8/2019 Session 3 TP2
10/30
Exploring ASP.NET / Session 3 / 10 of 30
Event Handlers - Example
void Page_Load(Object sender, EventArgs e){
//code for page load}
void buttonRefresh(Object sender, EventArgs e){
Page_Load(sender,e);}
8/8/2019 Session 3 TP2
11/30
Exploring ASP.NET / Session 3 / 11 of 30
Example Contd
8/8/2019 Session 3 TP2
12/30
Exploring ASP.NET / Session 3 / 12 of 30
_VIEWSTATE
Name
E- mail
Password
Submit
King
******
Name
E- mail
Password
Submit
8/8/2019 Session 3 TP2
13/30
Exploring ASP.NET / Session 3 / 13 of 30
Page_Load Event
Database Hello
World
8/8/2019 Session 3 TP2
14/30
Exploring ASP.NET / Session 3 / 14 of 30
Process Flow
Execution on
the server
1&23
4
5a
HTTP
Request
HTM
L
Page
Values
after
Postback
Changes are
processed
6
7
HTM
L
Page5b
User causes
Postback
8/8/2019 Session 3 TP2
15/30
Exploring ASP.NET / Session 3 / 15 of 30
ASP.NET Objects
8/8/2019 Session 3 TP2
16/30
Exploring ASP.NET / Session 3 / 16 of 30
ASP.NET Objects More
Details
8/8/2019 Session 3 TP2
17/30
Exploring ASP.NET / Session 3 / 17 of 30
ASP.NET Objects More
Details Contd
8/8/2019 Session 3 TP2
18/30
Exploring ASP.NET / Session 3 / 18 of 30
Virtual Directories ASP.NET application is a collection of text files that are
stored in a directory and its sub-directories on the Webserver
The base directory is called the virtual root, and thedirectory in which the application files are stored is calledthe virtual directory
The web server manages the virtual directory settings,permissions and user access
The advantage of using a virtual directory is that the userdoes not have to know the exactpath of a page when
making a request.
8/8/2019 Session 3 TP2
19/30
Exploring ASP.NET / Session 3 / 19 of 30
Virtual Directory - Permissions
Permissions
8/8/2019 Session 3 TP2
20/30
Exploring ASP.NET / Session 3 / 20 of 30
To create a virtual directory :
1. Open the Internet Services ManagerMMC
snap in.2. Expand Server name.
3. Right click on Default Web Site, and selectNew Virtual Directory from the pop up
menu.4. Click Next on the Welcome to the Virtual
Directory Creation Wizard.
Creating Virtual Directory
8/8/2019 Session 3 TP2
21/30
Exploring ASP.NET / Session 3 / 21 of 30
5. Enter an alias in the Virtual Directory Aliasscreen. Click Next.
6. Type in or Browse the physical path of theapplication root directory (which containsthe files for the web site) in the Web SiteContent Directory screen. Click Next.
Creating Virtual Directory
Contd
8/8/2019 Session 3 TP2
22/30
Exploring ASP.NET / Session 3 / 22 of 30
7. Set the appropriate access permissions
in the Access Permissions screen.
8. Click Finish to complete the creation of
the virtual directory.
Creating Virtual Directory
Contd
8/8/2019 Session 3 TP2
23/30
Exploring ASP.NET / Session 3 / 23 of 30
HTTP Protocol
HTTP Response
HTTP Request
The browser and the Web servercommunicate using the HTTP protocol .
When the browser opens a page from aWeb site, the browser establishes aconnection to the Web server andissues a request.
The Web server processes the request,and responds by sending the requiredpage. Thus, the communicationbetween the client and the server takesplace through a series of requests-and-responses.
8/8/2019 Session 3 TP2
24/30
Exploring ASP.NET / Session 3 / 24 of 30
Request & Response A request contains information about the client and some
parameters These parameters are essentially the data that is passed
from the client, and is to be processed at the server. A response contains the information requested by the client
browser ASP.NET recognizes this request-and-response
communication through two built-in objects that correspond
to the request and response messages of the HTTPprotocol. The Request object corresponds to the request message of
the HTTP protocol, and the Response object correspondsto the response message of the HTTP protocol.
8/8/2019 Session 3 TP2
25/30
Exploring ASP.NET / Session 3 / 25 of 30
Request & Response - ExampleInput.htm
Input Page
Enter your name
8/8/2019 Session 3 TP2
26/30
Exploring ASP.NET / Session 3 / 26 of 30
Request & Response - ExampleEnter your country name
8/8/2019 Session 3 TP2
27/30
Exploring ASP.NET / Session 3 / 27 of 30
Request & Response - ExampleWelcome.aspx
void Page_Load( Object src,EventArgs e){
String s,s1;s= Request.Form.Get ("name");Response.Write ("Hi " + s + ", Welcome to
ASP.NET!
");}
8/8/2019 Session 3 TP2
28/30
Exploring ASP.NET / Session 3 / 28 of 30
Request & Response
8/8/2019 Session 3 TP2
29/30
Exploring ASP.NET / Session 3 / 29 of 30
Summary The @ Page directive is used to specify attributes that affect the code
in the .aspxpage. The section is where most of the code for providing the
required functionality is written. There are two types of server controls:
HTML Controls Web Controls
All eventprocedures receive two arguments from the events: The event sender The class instance that holds data for the event
The _VIEWSTATE control is a hidden control that is added to theform when the form is submitted to the server.
It is possible to check whether a .aspxpage is posted back to theserver with the help of the IsPostBack property of the page.
8/8/2019 Session 3 TP2
30/30
Exploring ASP.NET / Session 3 / 30 of 30
Summary Contd ASP.NET has several built-in objects that are used to provide the
required functionality in an ASP.NET application. They are the following: Request Response Application Session Server ObjectContext
The base directory is called the virtual root, and the directory in whichwe store the application files is called the virtual directory.
The Request object corresponds to the request message of the HTTPprotocol, and the Response object corresponds to the responsemessage of the HTTP protocol.
The Form.Get method of the Request object is used to retrieve thedata submitted by the user.
The Redirect method of the Response object is used to redirect the
user to another page.