0% found this document useful (0 votes)
18 views8 pages

WT Unit6 ASP Net

ASP.NET is a Microsoft web framework for developing websites, web applications, and web services, first released in 2002. It offers advantages such as reduced costs, robust security, and efficient code management, with the latest version being ASP.NET Core, which is open-source and cross-platform. The document also details the components of the .NET framework, the ASP.NET page lifecycle, event handling, server controls, and web services development.

Uploaded by

fijajamage9503
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views8 pages

WT Unit6 ASP Net

ASP.NET is a Microsoft web framework for developing websites, web applications, and web services, first released in 2002. It offers advantages such as reduced costs, robust security, and efficient code management, with the latest version being ASP.NET Core, which is open-source and cross-platform. The document also details the components of the .NET framework, the ASP.NET page lifecycle, event handling, server controls, and web services development.

Uploaded by

fijajamage9503
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

UNIT – VI (ASP .

NET)
ASP.NET

It is a web framework designed and developed by Microsoft. It is used to develop websites, web applications
and web services. It provides fantastic integration of HTML, CSS and JavaScript. It was first released in January
2002. It is built on the Common Language Runtime (CLR) and allows programmers to write code using any
supported .NET language.

Why we should use ASP.NET?

ASP.NET is a web framework designed by Microsoft Inc. that is extensively used to build robust web
applications.

Following are some main advantages of ASP.NET which makes it better than other frameworks
available in the market:

 The ASP.NET framework is facilitated by a powerful toolkit and designer in the integrated
development environment of Visual Studio. Drag-and-drop server controls and auto-deployment are
only a couple of the features this versatile tool offers.
 ASP.NET framework reduces higher costs along with creating custom web applications with all
features.
 The most recent framework of ASP.NET is ASP.NET core which is an open-source, cross-platform,
and cloud-based internet-connected web application.
 ASP.NET core encourages the creation of effective web apps along with mobile apps and IoT apps.
 These applications offer improved efficiency by taking advantage of early linking, just-in-time
compilation, native optimization, and caching services straight out of the box.
 ASP.NET greatly decreases the amount of code needed to build massive applications with tighter
security and improved performance.
 Lesser code encourages the application to easily manage and effectively maintain.
 These applications have windows authentication which makes the applications more secure.
 In ASP.NET applications, source code and HTML files are together, so ASP.NET pages are easy to
manage and write. The source code is now being run on the computer. This gives the websites a lot
of strength and versatility.
 ASP.NET is strictly server-side programming, so the ASP.NET code will run on the server before it is
sent to the browser.
 These applications are language-independent, so it allows you to select the language that is best for
you.
 All processes are tightly supervised and handled by the ASP.NET runtime, meaning that if the
process is dead, a new process can be generated in place, which helps keep the applications
continuously ready to handle requests.
 ASP.NET helps in developing robust web application.

Components of .Net Framework 3.5


Components and their Description

(1) Common Language Runtime or CLR


It performs memory management, exception handling, debugging, security checking, thread execution,
code execution, code safety, verification, and compilation. The code that is directly managed by the CLR
is called the managed code. When the managed code is compiled, the compiler converts the source code

1
into a CPU independent intermediate language (IL) code. A Just In Time(JIT) compiler compiles the IL code
into native code, which is CPU specific.

(2) .Net Framework Class Library


It contains a huge library of reusable types. classes, interfaces, structures, and enumerated values, which
are collectively called types.

(3) Common Language Specification


It contains the specifications for the .Net supported languages and implementation of language
integration.

(4) Common Type System


It provides guidelines for declaring, using, and managing types at runtime, and cross-language
communication.

(5) Metadata and Assemblies


Metadata is the binary information describing the program, which is either stored in a portable executable
file (PE) or in the memory. Assembly is a logical unit consisting of the assembly manifest, type metadata,
IL code, and a set of resources like image files.

(6) Windows Forms


Windows Forms contain the graphical representation of any window displayed in the application.

(7) ASP.NET and ASP.NET AJAX


ASP.NET is the web development model and AJAX is an extension of ASP.NET for developing and
implementing AJAX functionality. ASP.NET AJAX contains the components that allow the developer to
update data on a website without a complete reload of the page.

(8) ADO.NET
It is the technology used for working with data and databases. It provides access to data sources like SQL
server, OLE DB, XML etc. The ADO.NET allows connection to data sources for retrieving, manipulating, and
updating data.

(9) Windows Workflow Foundation (WF)


It helps in building workflow-based applications in Windows. It contains activities, workflow runtime,
workflow designer, and a rules engine.

(10) Windows Presentation Foundation

2
It provides a separation between the user interface and the business logic. It helps in developing visually
stunning interfaces using documents, media, two and three dimensional graphics, animations, and more.

(11) Windows Communication Foundation (WCF)


It is the technology used for building and executing connected systems.

(12) Windows CardSpace


It provides safety for accessing resources and sharing personal information on the internet.

(13) LINQ
It imparts data querying capabilities to .Net languages using a syntax which is similar to the tradition query
language SQL.

ASP.NET Page Lifecycle

In ASP.NET, a web page has execution lifecycle that includes various phases. These phases include
initialization, instantiation, restoring and maintaining state etc. it is required to understand the page lifecycle
so that we can put custom code at any stage to perform our business logic.

Page Lifecycle stages

The following table contains the lifecycle stages of ASP.NET web page.

Stage Description

Page request This stage occurs before the lifecycle begins. When a page is requested by the user, ASP.NET
parses and compiles that page.

3
Start In this stage, page properties such as Request and response are set. It also determines the Request
type.

Initialization In this stage, each control's UniqueID property is set. Master page is applied to the page.

Load During this phase, if page request is postback, control properties are loaded with information.

Postback In this stage, event handler is called if page request is postback. After that, the Validate method
event handling of all validator controls is called.

Rendering Before rendering, view state is saved for the page and all controls. During the rendering stage, the
page calls the Render method for each control, providing a text writer that writes its output to the
OutputStream object of the page's Response property.

Unload At this stage the requested page has been fully rendered and is ready to terminate.at this stage
all properties are unloaded and cleanup is performed.

ASP.NET Web Pages

Web Pages is one of many programming models for creating ASP.NET web sites and web applications.

Web Pages provides an easy way to combine HTML, CSS, and server code:

Easy to learn, understand, and use

Uses an SPA application model (Single Page Application)

Similar to PHP and Classic ASP

VB (Visual Basic) or C# (C sharp) scripting languages

In addition, Web Pages applications are easily extendable with programmable helpers for databases, videos,
graphics, social networking and more.

ASP.NET Event Handling :

An event is an action or occurrence such as a mouse click, a key press, mouse movements, or any system-
generated notification. A process communicates through events. For example, interrupts are system-
generated events. When events occur, the application should be able to respond to it and manage it.
Events in ASP.NET raised at the client machine, and handled at the server machine. For example, a user clicks
a button displayed in the browser. A Click event is raised. The browser handles this client-side event by
posting it to the server.
The server has a subroutine describing what to do when the event is raised; it is called the event-handler.
Therefore, when the event message is transmitted to the server, it checks whether the Click event has an
associated event handler. If it has, the event handler is executed..
Page and Control Events
Common page and control events are:

4
 DataBinding - It is raised when a control binds to a data source.
 Disposed - It is raised when the page or the control is released.
 Error - It is a page event, occurs when an unhandled exception is thrown.
 Init - It is raised when the page or the control is initialized.
 Load - It is raised when the page or a control is loaded.
 PreRender - It is raised when the page or the control is to be rendered.
 Unload - It is raised when the page or control is unloaded from memory.
Event Handling Using Controls
All ASP.NET controls are implemented as classes, and they have events which are fired when a user performs
a certain action on them. For example, when a user clicks a button the 'Click' event is generated. For handling
events, there are in-built attributes and event handlers. Event handler is coded to respond to an event, and
take appropriate action on it.
By default, Visual Studio creates an event handler by including a Handles clause on the Sub procedure. This
clause names the control and event that the procedure handles.
The ASP tag for a button control:

<asp:Button ID="btnCancel" runat="server" Text="Cancel" />


The event handler for the Click event:

Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Handles btnCancel.Click

End Sub

An event can also be coded without Handles clause. Then, the handler must be named according to the
appropriate event attribute of the control.
The ASP tag for a button control:

<asp:Button ID="btnCancel" runat="server" Text="Cancel" Onclick="btnCancel_Click" />


The event handler for the Click event:

Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)

End Sub

5
ASP.NET Server Object and Control:
ASP.NET server controls are the primary controls used in ASP.NET. These controls can be grouped into the
following categories:
 Validation controls - These are used to validate user input and they work by running client-
side script.
 Data source controls - These controls provides data binding to different data sources.
 Data view controls - These are various lists and tables, which can bind to data from data
sources for displaying.
 Personalization controls - These are used for personalization of a page according to the user
preferences, based on user information.
 Login and security controls - These controls provide user authentication.
 Master pages - These controls provide consistent layout and interface throughout the
application.
 Navigation controls - These controls help in navigation. For example, menus, tree view etc.
 Rich controls - These controls implement special features. For example, AdRotator,
FileUpload, and Calendar control.
The syntax for using server controls is:

<asp:controlType ID ="ControlID" runat="server" Property1=value1 [Property2=value2] />

Properties of the Server Controls


ASP.NET server controls with a visual aspect are derived from the WebControl class and inherit all the
properties, events, and methods of this class.
The WebControl class itself and some other server controls that are not visually rendered are derived from
the System.Web.UI.Control class. For example, PlaceHolder control or XML control.
ASP.Net server controls inherit all properties, events, and methods of the WebControl and
System.Web.UI.Control class.
The following table shows the inherited properties, common to all server controls:

Property Description

AccessKey Pressing this key with the Alt key moves focus to the control.

Attributes It is the collection of arbitrary attributes (for rendering only) that do not correspond to
properties on the control.

BackColor Background color.

BindingContainer The control that contains this control's data binding.

BorderColor Border color.

6
BorderStyle Border style.

BorderWidth Border width.

ASP.NET Database Object Reference


Method Description
Database.Execute(SQLstatement [, parameters]) Executes SQLstatement (with optional parameters) such
as INSERT, DELETE, or UPDATE and returns a count of
affected records.
Database.GetLastInsertId() Returns the identity column from the most recently
inserted row.
Database.Open(filename) Opens either the specified database file or the database
Database.Open(connectionStringName) specified using a named connection string from
the Web.config file.
Database.OpenConnectionString(connectionString) Opens a database using the connection string. (This
contrasts with Database.Open, which uses a connection
string name.)
Database.Query(SQLstatement[, parameters]) Queries the database using SQLstatement (optionally
passing parameters) and returns the results as a
collection.
Database.QuerySingle(SQLstatement [, Executes SQLstatement (with optional parameters) and
parameters]) returns a single record.
Database.QueryValue(SQLstatement [, parameters]) Executes SQLstatement (with optional parameters) and
returns a single value.

7
ASP.NET Web Service:
A web service is a web-based functionality accessed using the protocols of the web to be used by the web
applications. There are three aspects of web service development:

 Creating the web service


 Creating a proxy
 Consuming the web service
Creating a Web Service

Creation:

1. Create a new website by selecting "ASP.NET Web Site" and giving it a suitable name.
2. service.cs file appears inside the solution with a default webmethod named as "HelloWorld()".
3. Right click on the webservice project and add a web reference instead of adding a normal
reference.
4. A window appears that displays a list of webservices knows to the solution.
5. Click on "Webservices in this solution"
6. a search progress bar appears and
7. Select the service that appears in the list
8. Progress bar appears once again.
9. Web method appears on the screen
10. Click on "Add reference" button. This would add localhost
11. Solution would have App_WebReference folder

Consumption or Usage:

1. Add a UI (.aspx) to the webservice project.


2. Add a button and a label to the form.
3. Double click the button to see the click event of the button.
4. Create an object of type service localhost.serviceName.
5. Write code to display the value returned by the webmethod on the label.
6. Execute the solution by setting the added aspx as the startpage.
7. Click on the button and the message "Hello World" would be displayed on the label.

You might also like