Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
Darshan Institute of Engineering & Technology for Diploma Studies Unit-1
1 Dept: CE AWT (3360706) Piyush Bhut
BASIC OF ASP.NET
Asp.net refers as Active Server Pages .net which is server side object oriented programming language.
Asp.net is language of Microsoft.net framework to develop web applications.
Benefits:-
Easier OOP Language
Quick Drag & Drop Control
Code Separation
Easier database operations
Version Compatibility
High Security
Easy application Development
Highly Integrated IDE
Asp.net uses to develop dynamic web pages, web services and web application.
Asp.net is built on the CLR(Common Language Runtime) that allows user to write Asp.net program
using any .net framework supported language like C#, VB, Visual C++, J# etc..
Asp.net also supports ADO.NET (ActiveX data object.Net) that helps to connect and work with data
stored in database.
Asp.net also provide everything Readymade such as Rich controls, Validation controls, Databound
controls, Ajax controls for developing easier, fast and highly dynamic web applications.
FEATURES OF ASP.NET
Simplified Programming Model: ASP.NET is a technology which can be implemented using any dotnet
language such as C#.Net or VB. Net
Side by side Execution: Side by side execution is the ability to run multiple version of an application or
component on the same computer
Server side Controls: ASP.NET technology has introduced rich powerful web server controls which are
capable to identify the clients’ browser and can render the HTML tags accordingly.
Performance: Architecture of the ASP.NET is designed in order to increase the performance of the
application.
Caching: It is used to maintain the result or output of the web-form temporarily.
Powerful Database Support: ASP.NET supports very large amount of database class and it also provide
the easy deployment of the connectivity with the application.
Web Services: With the help of ASP.NET we can also develop the web services, which are useful for the
communication of protocols, it can be also used by other application, it is an application components.
Simplified Form Validation: In other language we have to write so may line of codes to validate a
control, while in ASP.NET it becomes Easy and Simple for Deployment.
Simplified Deployment: With the help of the CLR, We can develop our applications in any language so
we don’t have to worry about programming language. Visual Studio provides all the functionality of
drag of controls, we deployment becomes fast and easy. We can easily configure IIS (Internet Information
Service).
Darshan Institute of Engineering & Technology for Diploma Studies Unit-1
2 Dept: CE AWT (3360706) Piyush Bhut
Rich Tool Box Support: ASP.NET supports a very high range of tools which can be easily implemented.
DIFFERENCES BETWEEN ASP.NET AND CLASSIC ASP
ASP.NET Classic ASP
ASP.NET is full featured object oriented programming.
It has full support of xml. This helps easy data
exchange.
It has limited oops support and not having built in
support for xml.
Various tools and compiler available. Microsoft Visual
studio makes your debugging job easier.
Very less development and debugging tool available.
Meaning that difficult to debug the code.
ASP.NET we can use either C# or VB.NET as server
side programming language.
ASP you can only do scripting using visual basic
scripting and java scripting.
Error handling is very good. Error handling is very poor.
ASP.NET gives you three tire architecture. It allows
you to keep your business logic, views everything
separate.
It has no high level programming structure. Mixed of
html and server side scripting.
In built validation controls. It has rich validation set -
custom validator, range validator, regular expression,
compare and require field validation control which
makes your job easier.
It has no in built validation control. Meaning that
validating page is difficult for developers.
It has state management support. In the classic ASP if you need to update code on the
existing page then it is mandatory to restart the
server to get reflect.
OOP Language Support. Scripting Language Support.
Inheritance Supports. Doesn't Support Inheritance.
Separate file for code and data both. Single file for code and data.
Machine.Config and Web.config both is configuration
file.
Doesn't have Configuration files.
Supports Custom Controls. Doesn't Support Custom Controls.
ADO.Net with XML integration. Simple ADO with limited functionalities.
WEB APPLICATIONS AND WEBPAGE
Web-Page/Web-Site Web-Application
A website is informational. OR website is defined by
its content.
A web application is interactive. OR web application is
defined by its interaction with the user.
Website we can create pages in multi programming
languages that mean we can create one page code in
C# and another page code in vb.net.
Web application we have chance of select only one
programming language during creation of project
either C# or VB.NET.
Web Sites won’t create any .csproj/.vbproj files in
project.
we create Web Application those will automatically
create project files (.csproj or .vbproj).
Darshan Institute of Engineering & Technology for Diploma Studies Unit-1
3 Dept: CE AWT (3360706) Piyush Bhut
We need to deploy both .aspx file and code behind
file.
If we want to deploy web application project we need
to deploy only .aspx pages there is no need to deploy
code behind files because the pre-compiled dll will
contains these details.
No need to recompile the site before deployment. We need to pre-compile the site before deployment.
If we make any code changes those files only will
upload there is no need to re-compile entire site.
If we make small change in one page we need to re-
compile the entire sites.
Example:- www.darshan.ac.in Example:- Google doc
COMPONENTS OF WEB APPLICATION
Web Form
ASP.NET Web Form is a programmable Web page (.aspx file).
Acts as a user interface (UI) of an ASP.NET application.
Consists of HTML, code and controls which are executed on a web server.
The user sees the result in the form of HTML generated by the web server.
Web Control
ASP.NET Web server controls are objects on ASP.NET Web pages that run when the page is requested.
Many Web server controls are similar to familiar HTML elements, such as buttons and text boxes.
Other controls have complex behavior, such as a calendar controls, and controls that you can use to
connect to data sources and display data.
Web.Config
Configuration file is used to manage various settings that define a website. The settings are stored in
XML files that are separate from your application code. Generally a website contains a single
Web.config file stored inside the application root directory.
There are number of important settings that can be stored in the configuration file. Some of the most
frequently used configurations, stored inside Web.config file are: Database connections, Caching
settings, Session States, Error Handling, Security.
Configuration file looks like this:
<configuration>
<connectionStrings>
<add name ="myCon" connectionString ="server= PRB-PC\SQLEXPRESSREPORT; database=Demo;
</connectionStrings>
</configuration/>
Machine.config
The machine.config file is the master configuration file on your system with a lot of default settings.
The settings of Machine.config file are applied to the whole asp.net applications on your server.
Each .NET Framework version has only one machine.config file.
Darshan Institute of Engineering & Technology for Diploma Studies Unit-1
4 Dept: CE AWT (3360706) Piyush Bhut
The machine.config would be to share values between many applications on the server such as SMTP
server settings.
Global.asax
The Global.asax file, also known as the ASP.NET application file, is an optional file that contains code
for responding to application-level events raised by ASP.NET.
Only one Global.asax file per application and it should be located in application’s root directory only.
Application-level events are: Application_Start, Application_End, Session_Start, Session_End.
CLIENT SERVER ARCHITECTURE
Three-tier (layer) is a client-server architecture in which the user interface, business process (business
rules) and data storage and data access are developed and maintained as independent modules or
most often on separate platforms.
Basically, there are 3 layers, tier 1 (presentation tier, GUI tier), tier 2 (business objects, business logic
tier) and tier 3 (data access tier). These tiers can be developed and tested separately.
Darshan Institute of Engineering & Technology for Diploma Studies Unit-1
5 Dept: CE AWT (3360706) Piyush Bhut
Presentation Layer
The Presentation Layer contains pages like .aspx where data is presented to the user or input is taken
from the user. The ASP.NET web site (the UI for the project) is called the Presentation Layer.
The Presentation Layer is the most important layer simply because it’s the one that everyone sees and
uses. Even with a well structured business and data layer, if the Presentation Layer is designed poorly,
this gives the users a poor view of the system.
Business Layer
A Business Layer contains business logic, validations or calculations related to the data.
Though a web site could talk to the data access layer directly, it usually goes through another layer
called the Business Layer. The Business Layer validates the input conditions before calling a method
from the data layer. This ensures the data input is correct before proceeding, and can often ensure
that the outputs are correct as well. This validation of input is called business rules, meaning the rules
that the Business Layer uses to make “judgments” about the data.
Data Layer
A Data Layer contains methods that help the Business Layer to connect the data and perform required
actions, whether to return data or to manipulate data (insert, update, delete and so on).
CREATING SIMPLE WEB APPLICATION IN ASP.NET INTRODUCTION TO VISUAL STUDIO
Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft. It is used to develop computer programs for Microsoft Windows, as well as web sites, web applications and web services.
Menu Bar and toolbar
File Contains commands for opening projects, closing projects, printing project data, etc.
Edit Contains commands such as cut, paste, find, undo, etc.
View Contains commands for displaying IDE windows and toolbars.
Project Contains commands for managing a project and its files.
Build Contains commands for compiling a program.
Debug Contains commands for debugging (i.e., identifying and correcting problems in a program) and running a program.
Test Contains commands for testing code.
Tools Contains commands for accessing additional IDE tools and options that enable customization of the IDE.
Windows Contains commands for arranging and displaying windows.
Help Contains commands for accessing the IDE’s help features.
Toolbox: The Toolbox window contains controls used to customize forms. Programmers can “drag and
drop” controls onto the form.
Darshan Institute of Engineering & Technology for Diploma Studies Unit-1
6 Dept: CE AWT (3360706) Piyush Bhut
Properties: The Properties window displays the properties for a form or control. Properties specify
information such as size, color and position.
Solution Explorer: The solution explorer window provides access to all the files in the solution.
CREATING A NEW WEB PROJECT (ASP.NET)
Select File->New Project within the Visual Studio 2008 IDE. This will bring up the New Project dialog.
Click on the “Visual Basic” node in the left hand side of the dialog box and choose the "ASP.NET Web
Application" icon:
Choose where you want the project to be created on disk. Then name it and hit ok.
Visual Studio will then create and open a new web project within the solution explorer. By default
it will have a single page (Default.aspx), web.config file. All project file-meta-data is stored within a
MSBuild based project file.
OPENING AN EXISTING WEB SITES
To open existing project go to File->Open->Project/Solution. Open the project folder which you want
and then double click on Microsoft Visual Studio Solution(.sln) file.
Darshan Institute of Engineering & Technology for Diploma Studies Unit-1
7 Dept: CE AWT (3360706) Piyush Bhut
BUILDING WEB SITES
Hit F5 to build and run the project in debug mode.
By default, ASP.NET Web Application projects are configured to use the built-in VS web-server when
run.
The default project templates will run on a random port as a root site (for example:
http://localhost:49665/Default.aspx)
Set up of work environment, Start page, the menu system, toolbars, the new project dialog box, graphical
designer, code designer
The new project window allows choosing an application template from the available templates.
When you start a new web site, ASP.NET provides the starting folders and files for the site, including
two files for the first web form of the site.
The file named Default.aspx contains the HTML and asp code that defines the form, and the file named
Default.aspx.cs (for C# coding) or the file named Default.aspx.vb (for vb coding) contains the code in
the language you have chosen and this code is responsible for the form's works.
The primary window in the Visual Studio IDE is the Web Forms Designer window. Other supporting
windows are the Toolbox, the Solution Explorer, and the Properties window.
You use the designer to design a web form, to add code to the control on the form so that the form
works according to your need, you use the code editor.
To change the Web Forms Designer from one view to another, click on the Design or source button.
To close a window, click on the close button on the upper right corner and to redisplay, select it from
the View menu.
To hide a window, click on its Auto Hide button; the window changes into a tab, to redisplay again click
on the Auto Hide button again.
When a new web form is created, Visual Studio automatically generates the starting HTML for the form
and displays it in Source view of the web forms designer. The Solution Explorer is used to add any other
files, folders or any existing item on the web site.
Darshan Institute of Engineering & Technology for Diploma Studies Unit-1
8 Dept: CE AWT (3360706) Piyush Bhut
To add a standard folder, right-click on the project or folder under which you are going to add the
folder in the Solution Explorer and choose New Folder.
To add an ASP.Net folder, right-click on the project in the Solution Explorer and select the folder from
the list.
To add an existing item to the site, right-click on the project or folder under which you are going to add
the item in the Solution Explorer and select from the dialog box.
WORKING WITH ASP.NET WEB FORMS TYPES OF ASP.NET FILES
File type Description
.asax The Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for responding to application-level events raised by ASP.NET.
.aspx An ASP.NET Web Forms page that can contain Web controls and presentation and
business logic.
.config A configuration file contains XML elements that represent settings for ASP.NET
features.
.cs, .vb Source code files (.cs or .vb files) that define code that can be shared between pages,
such as code for custom classes, business logic, HTTP modules, and HTTP handlers.
.dll A compiled class library file (assembly). In a Web site project, instead of placing
compiled assemblies in the Bin subdirectory, you can put source code for classes in
the App_Code subdirectory.
.master A master page that defines the layout for other Web pages in the application.
.mdb, .ldb An Access database file.
Darshan Institute of Engineering & Technology for Diploma Studies Unit-1
9 Dept: CE AWT (3360706) Piyush Bhut
.mdf A SQL Server Express database file.
.skin A skin file that contains property settings to apply to Web controls for consistent
formatting.
.sln A solution file for a Visual Studio project.
WEB FORM ROUND TRIP
The browser presents the user with a form, and the user interacts with the form, causing the form to
post back to the server.
However, since all processing that interacts with server components must occur on the server.
So this means that for each action that requires processing, the form must be posted to the server,
processed, and returned to the browser. This sequence of events is referred to as a round trip.
In Web Forms, most user actions such as clicking a button result in a round trip.
For that reason, the events available in ASP.NET server controls are usually limited to click-type events.
Most server controls expose a click event, one that requires an explicit user gesture.
STAGES IN WEB FORM PROCESSING
When a user request for Asp.net page, the page gone through many stages that is call its life cycle.
Various stages in ASP.Net Web Page
Stages What is done in Stages?
Load If current request is old one, the property of control is loaded with data from view and control state.
Page Request Asp.Net checks that request of the page is new or old, if new then it compiles and executes that page and if request is old, cached copy will be returned.
Page Initialization In page, each control is initialized. Themes will be loaded. If requested page is old then post back data is not loaded.
Darshan Institute of Engineering & Technology for Diploma Studies Unit-1
10 Dept: CE AWT (3360706) Piyush Bhut
Postback Event Handling
If request for the page is old one, then any event handler can be invoked.
Rendering All controls on the page are saved. During rendering, render method for each control on page and writes it to output stream object of page response property.
Start Request And Response properties are set and using IsPostBack property new or old request can be identified.
Unload Request and response properties of the page are unloaded and cleaning performed if required.
Validation After loading the page, the validation controls are used to invoke Validate method for error free access.
Asp.Net Pages Life Cycle Events
Events Working Of Events
PreInit First event of Asp.net Page Life cycle. It checks whether the page is processed for the first time or not. It also creates and recreates dynamic controls, sets master page and themes. It sets and gets profile property.
Init This event is raised after initialization of all controls and applying skin properties and initialize or read control properties.
Load This event is called to set control properties and establish database connections. Page class calls OnLoad event of web page after that calls event for each child control, until page is loaded.
ASP.NET OBJECTS (REQUEST, RESPONSE, SERVER, APPLICATION, SESSION)
Request Object: - Describes the methods, properties, and collections of the object that stores
information related to the HTTP request. This includes forms, cookies, and server variables.
Response Object: - Describes the methods, properties, and collections of the object that stores
information related to the server's response. This includes displaying content, manipulating headers,
setting locales, and redirecting requests.
Server Object: - Describes the methods and properties of the object that provides methods for various
server tasks. With these methods you can execute code, get error conditions, encode text strings,
create objects for use by the Web page, and map physical paths.
Application Object: - Describes the methods, properties, and collections of the object that stores
information related to the entire Web application, including variables and objects that exist for the
lifetime of the application.
Session Object: - Describes the methods, properties, and collections of the object that stores
information related to the user's session, including variables and objects that exist for the lifetime of
the session.