Você está na página 1de 60

ASP.

NET Framework

By

SRIRAM.B
Introduction to ASP.NET
 Introduction to ASP.NET  Special Folders
 Features of ASP.NET
- App_Code
 Difference between ASP &
ASP.NET - App_Theme
 ASP.NET Page Model - App_Data
 ASP.NET Page Events - App_Web References
 ASP.NET Page Directives
-App_Global Resources
 ASP.NET Page Post Back
Model -App_Local Resources
 ASP.NET Page Compilation
 ASP.NET ViewState
 Tracing & Debugging
Introduction to
ASP.NET
Introduction to ASP.NET
 Active Server Pages (ASP) is the server-side technology for creating dynamic
Web pages. The client’s browser interpreted the HTML tags and displayed the
output on the browser screen

 ASP.NET is a server-side Web technology that can be used to develop dynamic

and scalable Web applications. These applications can connect to databases,

interact with users and provide asynchronous services. It is used on a server to

build powerful Web Applications. ASP.NET offers several important advantages

over previous Web development models :


Introduction to ASP.NET..

 ASP.NET is a programming framework built on the common


language runtime that can be used on a server to build powerful Web
applications.

 The first version of ASP.NET offered several important advantages

over previous Web development models.

 ASP.NET 2.0 improves upon that foundation by adding support for

several new and exciting features in the areas of developer

productivity, administration and management, extensibility, and

performance:
Features of
ASP.NET
Features of ASP.NET 
 Better Language Support
 Better Controls
 Data Control
 Login Control
 Navigation Control
 WebParts
 Master Pages, Themes &
Skins
 Personalization
 Localization
 SQL Caching Invalidation
 AJAX
Features of ASP.NET ..
 Developer Productivity

It encapsulates common Web tasks into application services


and controls that can be easily reused across web sites.

It is possible to significantly reduce the amount of code and


concepts necessary to build common scenarios on the web
compared to previous versions.

 New Server Controls

The new server controls that enable powerful declarative


support for data access, login security, wizard navigation,
menus, treeviews, portals, and more.
Features of ASP.NET ..

 Data Controls

Data access in can be accomplished completely


declaratively (no code) using the new data-bound and data
source controls. There are new data source controls to
represent different data backends such as SQL database,
business objects, and XML, and there are new data-bound
controls for rendering common UI for data, such as gridview,
detailsview, and formview

 Navigation Controls

The navigation controls provide common UI for navigating


between pages in your site, such as treeview, menu, and
sitemappath.
Features of ASP.NET ..
 Login Controls

The new login controls provide the building


blocks to add authentication and authorization-
based UI to your site, such as login forms, create
user forms, password retrieval, and custom UI for
logged in users or roles.
 Web Part Controls

Web parts are an exciting new family of controls


that enable you to add rich, personalized content
and layout to your site, as well as the ability to
edit that content and layout directly from your
application pages.
Features of ASP.NET ..
 Master Pages

This feature provides the ability to define common structure


and interface elements for your site, such as a page header,
footer, or navigation bar, in a common location called a "master
page", to be shared by many pages in your site. In one simple
place you can control the look, feel, and much of functionality
for an entire Web site.

 Themes and Skins

The themes and skins features allow for easy customization of


your site's look-and-feel. You can define style information in a
common location called a "theme", and apply that style information
globally to pages or controls in your site
Features of ASP.NET ..
 Personalization

Using the new personalization services you can easily create customized
experiences within Web applications. The Profile object enables
developers to easily build strongly-typed, sticky data stores for user
accounts and build highly customized, relationship based experiences.

At the same time, a developer can leverage Web Parts and the
personalization service to enable Web site visitors to completely control
the layout and behavior of the site, with the knowledge that the site is
completely customized for them. Personalizaton scenarios are now easier
to build than ever before and require significantly less code and effort to
implement.
Features of ASP.NET ..
 Localization.

Enabling globalization and localization in Web sites today is


difficult, requiring large amounts of custom code and resources.

ASP.NET 3.0 and Visual Studio 2008 provide tools and


infrastructure to easily build Localizable sites including the
ability to auto-detect incoming locale's and display the
appropriate locale based UI.

Visual Studio 2008 includes built-in tools to dynamically


generate resource files and localization references. Together,
building localized applications becomes a simple and integrated
part of the development experience.
Features of ASP.NET ..
 Caching Improvements

ASP.NET 2.0 also now includes automatic database server


cache invalidation. This powerful and easy-to-use feature
allows developers to aggressively output cache database-driven
page and partial page content within a site and have ASP.NET
automatically invalidate these cache entries and refresh the
content whenever the back-end database changes.

Developers can now safely cache time-critical content for long


periods without worrying about serving visitors stale data.
 AJAX
You can update a web page without posting the page back to the
web server.
Diff. Between ASP
&ASP.NET
Diff. Between ASP & ASP.NET

ASP.NET ASP
 Event Driven Model with event
handlers running on the server.  No

 Separates the code from HTML  Spaghetti


 Compiled  Interpreted
 Configuration and deployment are  No
greatly simplified
 Does not support
 Supports OOPS OOPS

 Multi Threaded Apartment


 Single Threaded
Apartment
 Data Access using ADO.NET  Data Access using
ADO
ASP.NET 2.0
Page Model
Page Model
 Visual Component

- File containing static HTML, or ASP.NET Server Controls


or both

- Servers as a container for the static text and controls to


be displayed.
 Application Logic

- Code interacts with the web form

- Stored in Code-Behind files which has an “.aspx.vb” or


“.aspx.cs” extension.
Web Forms File Structure
Page Processing Mechanism V 1.1
Page Processing Mechanism V 2.0
Page Directives
Web Page Code Model
Inline & Code Behind
 Inline
It executes a statement or series of statements. It is marked by <%
and %>
The code is in a separate “Script” section of the same file as the
HTML content.

File Options File Created


Web Form .aspx
Master Page .master
WebUserControl .ascx
WebService .asmx
Inline & Code Behind..
 Code Behind
It contain all the programming logic for a single web page.
Each web page in a web application has its own code-behind
page by default.

File Options File Created


Web Form .aspx , .aspx.cs /.aspx.vb
Master Page .master, .master.cs / .master.vb
WebUserControl .ascx , .ascx.cs / .ascx.vb
WebService .asmx, .asmx.cs/ .asmx.vb
Web Page Processing
 Processing Stages

Initialize -> Process -> Dispose

 Page Life Cycle

- Page Init ->

- Page Load (Load View State, Load Post Data, Load


controls, Raise Post Back Event) -> Validate -> Handle
Events ->

- Page PreRender -> (Save View State) -> Page Render ->

- Dispose -> UnLoad


Web Page Processing..

 Page_Init

ASP.NET page framework restores the control


properties and post back data
 Page_Load

Restores control values and reads and updates control


properties
 Page _PreRender

 Page_UnLoad
ASP.NET Page
Events
ASP.NET Page Events
 PreInit
 Init
 InitComplete
 PreLoad
 Load
 LoadComplete
 PreRender
 PreRenderComplete
 Unload
ASP.NET Page
Directives
ASP.NET Page Directives
 A directive controls how the page is compiled.
 The directives in ASP.NET are :-
 Page
Defines the page specific attributes used by ASP.NET page
parser & compiler.

<%@ Page Language =”VB” AutoeventWireup = “false”


CodeFile=”Default.aspx.vb” Inherits=”_Default”%>
 Master
Defines the master page specific attributes used by ASP.NET
page parser & compiler.

<%@ Master Language=”VB”


codeFile=”MasterPage1.master.vb”
AutoeventWireup = “false” Inherits =”MasterPage” %>
ASP.NET Page Directives
 Control
Defines the control specific attributes used by ASP.NET
page parser & compiler, can be included in .ascx file.

<%@ Control Language=”VB” CodeFile =


“WebUserControl.ascx.vb” Inherits =”WebUserControl”
Explicit = “True” Description=”Registration Control”%>

 Import

Explicitly imports a namespace into a page / user control.

<%@Import Namespace =”System.Data” %>

<%@Import Namespace =”System.Data.SqlClient” %>


ASP.NET Page Directives
 Implements
Indicates that current page or user control implements the
specified .NET Framework interface.
<%@ Implements interface
=”System.Web.UI.IValidator”%>
 Register
Associates aliases with namespaces and class names for
notations in custom server control.
<%@ Register TagPrefix =”MyTag”
Namespace=”MyName:MyNamespace”
Assembly=”MyAssembly”%>
 Reference
Declares that another ASP.NET page or user control should
be compiled along with active page or control.
<%@ Reference VirtualPath=”~/MyControl.ascx”%>
ASP.NET Page Directives
 Assembly

Links the assembly to the current page during compilation,


making all the assembly's classes and interfaces available for
use on the page.It supports two attributes Name & Src.
<%@Assembly Name = “MyAssembly”%>
<%@Assembly Src = “MyAssembly.vb”%>
 OutputCache
Controls the output caching polices of an ASP.NET page or user
control.
<%@OutputCache Duration =”180” VaryByParam=”None”%>
ASP.NET Page Postback
Model
ASP.NET Page Postback Model

 It provides a mechanism for sending control properties on web


pages from the Web browser to Web server and for restoring
those values when a response is sent back from the Web server to
Web browser.

 Designed to provide stateful rendering of dynamic content on a


web page, require minimal development effort.

 Following Types are :-


 Round-Trip Processing
 AutoPostBack Properties
 EnableViewState Properties
 Cross-Page Postbacks
ASP.NET Page Postback Model..
 Round-Trip Processing

Enables Web server controls to retain their values over multiple


requests to the server, even though the underlying HTTP mechanism are
stateless.

Enables you to develop web pages as if they are stateful application, by


posting information from browser to server, where server side events will
be raised, and by repopulating control properties in response to the
posting operations.

 AutoPostBack Property

Some Web server controls support the AutoPostBack property. Eg.


DropDownList

Controls whether user interaction with the control should invoke a round
trip requests to the server.
ASP.NET Page Postback Model..
 EnableViewState

Determines whether the control should retain its state for the
duration of postback, so you have to set the property to “true”
 Cross-Page Postbacks

If you want to post the values on one page to another page for
processing you have to configure “Postback Url” properties.
Page Navigation by Cross Page
Posting
 A page can be posted to another page where the
posted values can be retrieved.
 When the previous page is accessed, view-state is
re-populated to an instance of posting page.
ASP.NET Page
Compilation
ASP.NET Engine

.ASPX File
Generate
a Page Class
ASP.NET
ViewState
ASP.NET View State

 The current property settings of an ASP.NET page and those of any


ASP.NET server controls contained within the page.

i.e., Automatic Persistence of form data or contents is known as


view state.

 ASP.NET can detect when a form is requested for the first time
versus when the form is posted (sent to the server), which  allows
you to program accordingly. It is stored in HTML hidden fields.

<input type=”hidden” name=”_VIEWSTATE” value=”abcd” />

 The disadvantages of view state is during page loading & posting


performance decreases, it stores data in hashed format it will be
tampered easily.
Tracing & Debugging

Tracing &
Debugging
Tracing & Debugging
 Tracing
To trace the process of an application. It is useful in error
detection.
Tracing can be enabled at the page level by adding trace
attribute to the Page.
<%@ Page Trace = “True” %>
You can add own trace message using Trace.Warn Methods
Trace.Warn(“Page Loaded”)
 Debugging

To view the error message during page execution you have enable
for the page or entire application.
For Page Level - <% Page Debug=”True” %>
For Application Level in web.config file - <compilation debug = “true”>
Special Folders
APP Data
APP Code
Web Configuration
Code Access
Themes and Skins
Resource Folders
Local Resource File
Global Resource Files
Set Resource Data
App_WebReferences
Session Ends
Exercise
Relax

Você também pode gostar