ASP.Net: An Overview
We can use full featured programming language such as C# or VB.NET to build web applications easily. ASP.Net builds interactive, data-driven web applications over the internet. It includes a large number of controls like text boxes, buttons, and labels for assembling, configuring, and manipulating code to design and develop HTML Web pages.
ASP.Net was initially released in January 2002. The initial version was 1.0 of the .NET Framework. It is the successor to Active Server Pages (ASP). ASP.NET is based on the Common Language Runtime (CLR). CLR allows programmer to write ASP.NET code using any .NET supported language.
ASP.Net framework architecture is based on three components: The Language, The Library, and The CLR.
The Language: Dot net framework support different languages to write codes. We can use C# or VB.net to develop web applications.
The Library: Dot net framework consists of a set of class libraries.
System.Web is the most common class library used in asp.net web application development
The CLR: Common Language Runtime (CLR) is the main part of dot net architecture. It performs all main activities of the framework. It performs activities like exception handling and garbage collection.
An ASP.NET application includes several items: the web content files (.aspx), source files (.cs files), assemblies (.dll and .exe files), data source files (.mdb files), references, icons, user controls and miscellaneous other files and folders. All these files that build up the website are contained in a Solution. The contents of a project are compiled into an assembly as an executable file (.exe) or a dynamic link library (.dll) file.
Code Behind File: This concept separates design and coding. Because of this separation ASP.Net application is easy to maintain. The general file type of an ASP.Net file is
.aspx. Let us assume that we have a web page called
MyWebPage.aspx. There will be another file called
MyWebPage.aspx.cs which denotes the code part of the page. Visual Studio IDE creates separate files for each web page, one for the design and another for respective code.
State Management: It provides the facility to control state management. HTTP is known as stateless protocol. Let us take an example of a shopping cart application. Here, after deciding the purchase items when a user finally wants to buy from the site, he will press the submit button. The application needs to remember all the items the user selected for the purchase. This is known as remembering the state of an application at specific point in time. HTTP is a stateless protocol. When the user goes to the purchase page, HTTP will not store the information on the cart items. Additional coding needs to be done to ensure that the cart items can be carried forward to the purchase page. Such an implementation can become complex at times. But here, it can do state management on your behalf. So that ASP.Net can remember the cart items and pass it over to the purchase page.
Caching: It can implement the concept of Caching. Caching improves the performance of the application. With the help of caching frequently requested pages by the user can be stored in a temporary location. These pages can be retrieved faster and fast responses can be sent to the user.
ASP.Net Page Life Cycle
An ASP.NET page goes through a life cycle and performs a series of processing steps. These are: initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. To understand the page life cycle is essential so that we can write appropriate code at the appropriate life-cycle stage for the effect we intend.
The page request step comes before the page life cycle begins. When the user request for a page, ASP.NET decides whether the page needs to be parsed and compiled (therefore beginning the life of a page), or just a cached version of the page can be sent in response without running the page.
Page properties such as Request and Response are set in start stage. In this step, the page also decides whether the request is a postback or a new request and sets the
At initialization stage all page controls are available and
UniqueID property of each control is set. Master page and themes are also applied to the page, if applicable. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.
At the time of page load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.
Postback event handling
Control event handlers are called only if the request is a postback. Then the
Validate method of all validator controls is called, which sets the
IsValid property of individual validator controls and of the page. (NOTE: The handler for the event that caused validation is called after validation.)
View state is saved for the page and all controls before rendering. During the stage of rendering the page calls the Render method for each control, providing a text writer that writes its output to the
OutputStream object of the Response property of the page.
The Unload event occurs after the page has been fully rendered, sent to the client, and is ready to be disposed. At this moment, Response and Request etc. properties of the page are unloaded and cleanup is performed.
ASP.Net Page Life Cycle Events
At each stage of the ASP.Net Page life cycle, the page raises some events that we can handle to run our own code. For control events, we bind the event handler to the event either by declaration using attributes such as onclick or by writing code.
Pages also support automatic event wire-up where ASP.NET looks for methods with particular names and automatically runs those methods when certain events are raised. For example, if the
AutoEventWireup attribute of the
@Page directive is set to true, page events are automatically bound to methods that use the naming convention of
Page_event, such as
PreInit: It checks the
IsPostBack property and determines whether the page is a postback. It sets the themes and master pages, creates dynamic controls, and gets and sets profile property values. This event can be handled by overloading the
OnPreInit method or creating a
Init: It initializes the control property and build the control tree. This event can be handled by overloading the
OnInit method or creating a
InitComplete: This event allows tracking of view state. All the controls turn on view-state tracking.
LoadViewState: This event helps in loading of view state information into the controls.
LoadPostData: The contents of all the input fields are defined with the
<form> tag are processed.
PreLoad: This event raises before the post back data is loaded in the controls. This event can be handled by overloading the
OnPreLoad method or creating a
Load: This event is raised for the page first and then recursively for all child controls. The controls in the control tree are created. This event can be handled by overloading the
OnLoad method or creating a
LoadComplete: When the loading process is completed, control event handlers run, and page validation takes place. This event can be handled by overloading the
OnLoadComplete method or creating a
PreRender: This event occurs just before the output is rendered. Pages and controls can perform any updates before the output is rendered by using it.
PreRenderComplete: As the PreRender event is recursively fired for all child controls, this event ensures the completion of the pre-rendering phase.
SaveStateComplete: control state on the page is saved. Personalization, control state and view state information is saved. The HTML markup is generated. This stage can be handled by overriding the
Render method or creating a
UnLoad: UnLoad is the last phase of the page life cycle. It raises the UnLoad event for all controls recursively and lastly for the page itself. Final cleanup is done and all resources and references such as database connections are freed. This event can be handled by modifying the
OnUnLoad method or creating a
ASP.Net Web Development
ASP.NET offers three frameworks for creating web applications: Web Forms, ASP.NET MVC, and ASP.NET Web Pages. Each framework targets a different development style. The one you choose depends on a combination of your programming assets (knowledge, skills, and development experience), the type of application you’re creating, and the development approach you’re comfortable with.
ASP.NET Web Forms allows you to build dynamic websites using a familiar drag-and-drop, event-driven model. It provides a design surface and hundreds of controls and components so that you can rapidly build sophisticated, powerful UI-driven sites with data access.
ASP.NET MVC provides a powerful way to build dynamic websites on the basis of patterns that enables a clean separation of concerns. It gives you full control over markup for agile development with ease. MVC includes so many features that enable fast, TDD-friendly development for creating sophisticated applications based on latest web standards.
ASP.Net Web Pages
ASP.NET Web Pages and the Razor syntax provide a fast, approachable, and lightweight medium to bind server code with HTML to create dynamic web content. Database connection, embedding video, link to social networking sites, and many more features are included that helps a lot to create beautiful sites that conform to the latest web standards.
Less Coding: ASP.NET requires less coding for application development.
JIT: Just-in-time compilation, early binding and caching services are available.
Library: a large library of built-in classes is available to use. This significantly reduces the amount of coding required.
CLR: supports common language runtime. It can support several dot net languages such as C#, VB, etc.
Fast: Execution is fast. The ASP.net application is located in the server in compiled form. This reduces response time.
Secure: Security features such as Windows authentication and form authentication are present.
Easy Database Integration: easy to integrate ASP.NET with ADO.NET. This streamlines database functionalities for websites.
Code-behind file: ASP.NET separates presentation and programming logic with the use of code-behind classes.
Was this article helpful? Must share your views in the comment section below.
For more informative and updated technical articles, keep visiting our Tech Blogs.
2 thoughts on “ASP.Net | Architecture | Life Cycle | Events | Web Development”
As the admin of this site is working, no uncertainty very quickly it will be well-known, due to its quality contents.
Magnificent beat ! I wish to visit your web site again and again. i already subscribe for this blog website.
I had been tiny bit acquainted of this and your broadcast offered bright clear idea