Introduction to ASP NET 3 5 Lection 1

  • Slides: 68
Download presentation
Introduction to ASP. NET 3. 5 Lection 1: Web Forms Sergey Sidorov Ph. D

Introduction to ASP. NET 3. 5 Lection 1: Web Forms Sergey Sidorov Ph. D student, computer software chair Computer Science department

Agenda �Introduction to ASP. NET �Web Forms �Summary

Agenda �Introduction to ASP. NET �Web Forms �Summary

What is ASP. NET 3. 5? �An integrated suite of components that combines the

What is ASP. NET 3. 5? �An integrated suite of components that combines the building blocks of the Web �Markup languages �HTTP-with proven object-oriented methodolody

ASP. NET v. s. earlier web development platforms �ASP. NET is completely object-oriented programming

ASP. NET v. s. earlier web development platforms �ASP. NET is completely object-oriented programming model �ASP. NET gives ability to code in any. NET language �ASP. NET is dedicated to high perfomance

7 Facts about ASP. NET is integrated with the. NET Framework ASP. NET is

7 Facts about ASP. NET is integrated with the. NET Framework ASP. NET is compiled, not interpreted ASP. NET is Multilanguage ASP. NET is hosted by the Common Language Runtime 5. ASP. NET is object-oriented 6. ASP. NET is multidevice and multibrowser 7. ASP. NET is easy to deploy and configure 1. 2. 3. 4.

7 Facts about ASP. NET

7 Facts about ASP. NET

Releases of ASP. NET � 1. 0 � 1. 1 � 2. 0 �

Releases of ASP. NET � 1. 0 � 1. 1 � 2. 0 � 3. 5

ASP. NET 2. 0 �More rich controls (more than 40 new controls) �Master pages

ASP. NET 2. 0 �More rich controls (more than 40 new controls) �Master pages (reusable page template) �Themes (defining appearance characteristics) �Security and memberships �Data source controls (easy binding custom data container) �Profilers (store user-specific info in database)

ASP. NET 3. 5 �LINQ and AJAX �LINQ (Language integrated query) �Allows to write

ASP. NET 3. 5 �LINQ and AJAX �LINQ (Language integrated query) �Allows to write C# or Visual Basic code that manipulated in-memory data in muсh the same way query a database �AJAX (Asynchronous Java. Script and XML) �Programming asynchronous requests from client part to server

Difference of ASP. NET AJAX

Difference of ASP. NET AJAX

ASP. NET 3. 5

ASP. NET 3. 5

ASP. NET files descriptions �. aspx – web pages (user interface and application code)

ASP. NET files descriptions �. aspx – web pages (user interface and application code) �. ascx – user controls. �. asmx or. svc – ASP. NET web services �web. config – XML-based configuration file �global. asax – global application file �. cs – code-behind files that contain C# code

How a page class is considered?

How a page class is considered?

Web Forms

Web Forms

Web Forms �ASP. NET pages officially known as web forms �A vital part of

Web Forms �ASP. NET pages officially known as web forms �A vital part of ASP. NET application Page processing �Web application executes on server �Web applications are stateless

HTML forms

HTML forms

HTML forms

HTML forms

HTML forms �User click the submit button, �Browser collects values of controls, �Pastes it

HTML forms �User click the submit button, �Browser collects values of controls, �Pastes it together in a long string, �String is sent back using HTTP POST operation, In our case

HTML forms �You can look up by values in the Request. Form In our

HTML forms �You can look up by values in the Request. Form In our case

Dynamic User Interface �Almost all web control properties are readable and writable �An easier

Dynamic User Interface �Almost all web control properties are readable and writable �An easier way to add a Label �Updating its properties

Advantages of second case �It is much easier to write �Control-based code is much

Advantages of second case �It is much easier to write �Control-based code is much easier to place inside page �Control model hides the low-level HTML details

The ASP. NET Event Model �Your page runs for the first time. �ASP. NET

The ASP. NET Event Model �Your page runs for the first time. �ASP. NET creates page and controls objects, �initialization code executes, �Page is rendered to HTML and returned to the client �Page objects are released from server memory

ASP. NET Event Model �User does something that triggers a postback �Page is submitted

ASP. NET Event Model �User does something that triggers a postback �Page is submitted with all page data �ASP. NET intercepts the returned page and re-create the page objects �Taking care to return them to the last state �ASP. NET raises events (such as Button. Click) �Performing server side operation �Modified page is rendered to HTML and returned to the client

View state The next time the page is posted back, ASP. NET follows these

View state The next time the page is posted back, ASP. NET follows these steps: �Re-create the page and control objects based on defaults �Desirialize the view information and updates all the controls �Adjusting the page according to the posted back date �Event-handling code can get involved

View state

View state

View state

View state

XHTML Compliance ASP. NET 3. 5 web controls are compliant with XHTML 1. 1.

XHTML Compliance ASP. NET 3. 5 web controls are compliant with XHTML 1. 1. standard �XHTML 1. 1. doesn’t add any functionality in your page �XHTML 1. 1. allows to validate errors �Valid XML documents

Document Type Definition �Every XHTML document should begin with a doctype (document type definition)

Document Type Definition �Every XHTML document should begin with a doctype (document type definition)

Web Forms Processing Stages �Page framework initialization �User code initialization �Validation �Event handling �Automatic

Web Forms Processing Stages �Page framework initialization �User code initialization �Validation �Event handling �Automatic data binding �Cleanup

Web Form Processing Stages

Web Form Processing Stages

Page Framework Initialization �ASP. NET first creates a page �It generates all controls �If

Page Framework Initialization �ASP. NET first creates a page �It generates all controls �If it is not firs request �Desterilize view state information and applies it to the page �Page. Init event is fired ( rarely handed) it is too early

User Code Utilization �Page. Load event is fired �Page. Load event is always fired.

User Code Utilization �Page. Load event is fired �Page. Load event is always fired. (not only in first case) �Is. Post. Back property of page

Validation �ASP. NET includes validation controls that can automatically validate other user input controls

Validation �ASP. NET includes validation controls that can automatically validate other user input controls and display error messages �Events fire after page loaded but before any other events take place �You can use Page. Is. Valid property

Event Handling � 2 types of events �Immediate response events: clicking button, image region

Event Handling � 2 types of events �Immediate response events: clicking button, image region �Change events: changing selection in a control or the text in the textbox. Fire immediately if Auto. Post. Back is true. Otherwise they fire next time the page is posted back

Change Text, Click Button �Page. Init �Page. Load �Text. Box. Text. Changed �Button. Click

Change Text, Click Button �Page. Init �Page. Load �Text. Box. Text. Changed �Button. Click �Page. Pre. Render �Page. Unload

Automatic Data Binding �Using Data Source controls � 2 types of data souse operation

Automatic Data Binding �Using Data Source controls � 2 types of data souse operation �Before Page. Pre. Render (inserts, deletes updates) �After Page. Pre. Render (Performing queries) filing data

Cleanup After rendering page to HTML �Page. Unload event is fired �Page objects are

Cleanup After rendering page to HTML �Page. Unload event is fired �Page objects are available but page is rendered and can’t be changed

The Page As a Control Container �Web form renders itself and then asks all

The Page As a Control Container �Web form renders itself and then asks all the controls on page render themselves �Each control can contain child controls �Each is also responsible for their rendering code

The Page As a Control Container �When ASP. NET first creates a page, it

The Page As a Control Container �When ASP. NET first creates a page, it inspects the. aspx file. �For each element with runat=“server” it creates and configured control object �Adds this control as a child control of the page �Page. Controls collects all page controls

Showing the Control Tree �Rule don’t use Response. Write() �Add this code to the

Showing the Control Tree �Rule don’t use Response. Write() �Add this code to the Page. Load event

Showing the Control Tree

Showing the Control Tree

Showing the Control Tree �When you run this page you won’t see full list

Showing the Control Tree �When you run this page you won’t see full list of controls

Showing the Control Tree �ASP. NET adds Literal. Control objects �Literal. Control objects don’t

Showing the Control Tree �ASP. NET adds Literal. Control objects �Literal. Control objects don’t provide much in the way of functionality

Showing the Control Tree �Showing all controls

Showing the Control Tree �Showing all controls

Showing the Control Tree

Showing the Control Tree

Page Header �You can transform any HTML element into server control with runat=“server” attribute

Page Header �You can transform any HTML element into server control with runat=“server” attribute �Page can contain HTMLHead controls for access from server to tag <head> �Allows to change page rendering �Title �Style. Sheet �Controls

Page Header �Example of changing parameters

Page Header �Example of changing parameters

Dynamic Control Creation �Element is added to the end of collection �To get more

Dynamic Control Creation �Element is added to the end of collection �To get more control use Place. Holder – house of controls

Dynamic Control Creation �Dynamics controls will exist until the next post back �ASP. NET

Dynamic Control Creation �Dynamics controls will exist until the next post back �ASP. NET will not re-create dynamically added controls �For recreation of control multiple time use Page. Load event (using View State)

Dynamic Control Creation �Deleting Control �Adding events handlers for dynamic controls

Dynamic Control Creation �Deleting Control �Adding events handlers for dynamic controls

The Page Class �All web pages are instances of ASP. NET Page class �It

The Page Class �All web pages are instances of ASP. NET Page class �It is placed System. Web. UI namespase �Useful properties �Session �Application �Cache �Request �Responce �Server �User �Trace

Session, Application and Cache �Session stores any user-specific information that needs to persist between

Session, Application and Cache �Session stores any user-specific information that needs to persist between web-page request �Storing: user name, ID, shopping card �Application stores information that is global for all ASP. NET application �Cashe stores global information. Provides much more scalable mechanism because ASP. NET can remove information from server

Request �Represent the value and prototype of HTTP request �Contains �All URL parameters �All

Request �Represent the value and prototype of HTTP request �Contains �All URL parameters �All information sent by client �All information can be found in Control model �You can use it for examining of �Type browser �Getting access to user cookies

Request

Request

Request

Request

Request

Request

Response �Presents web’s server response to a client request �Doesn’t play nearly as central

Response �Presents web’s server response to a client request �Doesn’t play nearly as central role �Server. Transfer for redirect is qucker

Response

Response

Responce

Responce

Responce

Responce

Server

Server

Server �Map. Path() method converts relative path to the physical path �HTML and URL

Server �Map. Path() method converts relative path to the physical path �HTML and URL encoding

User �User object presents information about the user making request. �You can authenticate the

User �User object presents information about the user making request. �You can authenticate the user making request based on Windows account information

Trace

Trace

Trace

Trace

Summary �You learned: �Introduction to ASP. NET �Web Forms

Summary �You learned: �Introduction to ASP. NET �Web Forms

Reference �ASP. NET 3. 5 in C# 2008

Reference �ASP. NET 3. 5 in C# 2008