Professional Documents
Culture Documents
unit1
unit1
NET
Page 1
UNIT-1 Introduction to ASP.NET
When the client enters the URL of the web application in the browser, and
submits the request the web server which hosts the web application
receives therequest.
The request is then processed by the application.
The application generates, the HTML and hands it over to the IIS (web
server).
Finally, IIS sends the generated HTML to the client, who made the initial
request.
The client browser will interpret the HTML and displays the user interface.
All this communication happens over the internet using HTTP protocol.
HTTP stands for Hyper Text Transfer Protocol.
A protocol is a set of rules that govern how two or more items communicate.
UNIT-1 Introduction to ASP.NET
1)Single -File page model:- In Single -File page model,the HTML markup and
functionality of a web application are implemented in same File. In single -File coding
approach, developers write code directly in the.aspx page of the application.A major
drawback of the single-File code model is that writing code in a single file, so it is very
difficult to read and manage the webpages.
Example:-
See code (Design) .aspx
File:-Inline Coding model
UNIT-1 Introduction to ASP.NET
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender,
System.EventArgs e) {Label1.Text = "Your Name is : "
+
TextBox1.Text.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Asp.Net Inline Coding Model Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1"
runat="server" Font-Size="Larger"
ForeColor="Crimson"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Text="Enter
your name:"
AssociatedControlID="TextBox1"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Click" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter your name: "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
The .aspx.cs page will contain the business logic (server side code):
using System;
using System.Configuration;using System.Data;
using System.Linq;using System.Web;
using
System.Web.Securit
y;using
System.Web.UI;
using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
}
protected void Button1_Click(object sender, EventArgs e)
UNIT-1 Introduction to ASP.NET
{
Response.Write("Welcome to our website");
}
}
Code Behind separates user interface from actual programming. This means graphic
designers would look for only design matters while programmers work their way.
Each specialized person work in their irrespective area and doesn't disturb each
other to perform optimized work.
Well there is no performance difference between inline code and code-behind model.
There are multiple components in the architecture of Common Language Runtime. Details about
these are given as follows:
Base Class Library Support: The Common Language Runtime provides support for the base class
library. The BCL contains multiple libraries that provide various features such
as Collections, I/O, XML, DataType definitions, etc. for the multiple .NET programming languages.
Thread Support: The CLR provides thread support for managing the parallel execution of
multiple threads. The System.Threading class is used as the base class for this.
COM Marshaller: Communication with the COM (Component Object Model) component in the
.NET application is provided using the COM marshaller. This provides the COM interoperability
support.
Type Checker: Type safety is provided by the type checker by using the Common Type System
(CTS) and the Common Language Specification (CLS) that are provided in the CLR to verify the
types that are used in an application.
Exception Manager: The exception manager in the CLR handles the exceptions regardless of
the .NET Language that created them. For a particular application, the catch block of the
exceptions are executed in case they occur and if there is no catch block then the application is
terminated.
Security Engine: The security engine in the CLR handles the security permissions at various
levels such as the code level, folder level, and machine level. This is done using the various tools
that are provided in the .NET framework.
Debug Engine: An application can be debugged during the run-time using the debug engine.
There are various ICorDebug interfaces that are used to track the managed code of the application
that is being debugged.
JIT Compiler: The JIT compiler in the CLR converts the Microsoft Intermediate Language (MSIL)
into the machine code that is specific to the computer environment that the JIT compiler runs on.
The compiled MSIL is stored so that it is available for subsequent calls if required.
Code Manager: The code manager in CLR manages the code developed in the .NET framework i.e.
the managed code. The managed code is converted to intermediate language by a language-
specific compiler and then the intermediate language is converted into the machine code by the
Just-In-Time (JIT) compiler.
UNIT-1 Introduction to ASP.NET
Garbage Collector: Automatic memory management is made possible using the garbage collector
in CLR. The garbage collector automatically releases the memory space after it is no longer
required so that it can be reallocated.
CLR Loader: Various modules, resources, assemblies, etc. are loaded by the CLR loader. Also, this
loader loads the modules on demand if they are actually required so that the program
initialization time is faster and the resources consumed are lesser.
Inheritance
Inheritance is a key component of OOP (Object-Oriented
(Object Programming).
Inheritance
itance refers to a class's capacity to derive features and traits from another class.
We inherit properties from other classes when we write a class.
So, when we build a class, we don't have to repeat all of the properties and functions because
they can be inherited from another class that has them.
Inheritance allows the user to reuse code as much as possible, reducing repetition.
Examples: Class ElectricCar inherits from Car but adds specific methods like chargeBattery.
Polymorphism
The ability of an entity
tity (object or function) to change its form or behavior based on the
situation.
Treating objects of different types similarly provides flexibility and simplifies code.
Examples: By modifying its behavior, a print() function can handle various data types llike
strings, integers, and objects.
Dynamic Binding
At runtime, the process of binding a function call to the correct implementation based on the
type of the object at that time.
This allows for more flexible behavior and late-function
late binding.
Example: Depending on the object calling it at runtime, the eat() function in Animal may have
different implementations for Cat and Dog.
Message Passing
UNIT-1 Introduction to ASP.NET
In object-oriented programming, the communication method between objects.
Messages (function calls) are sent between objects with data as arguments, activating certain
behaviors.
This encourages modularity and decoupling, resulting in more manageable and reusable
code.
Example: To initiate the window's close function, a Button object clicks on a Window object.
Event-driven programming (EDP) is a programming paradigm where external events determine the
flow of program execution. These events come in different shapes: user actions (e.g., button clicks,
keyboard inputs), system events (like a finished file download), messages from other programs,
sensor outputs, etc.
Page request: This stage occurs before the lifecycle begins. When a page is requested
by the user, ASP.NET parses and compiles that page.
Starting of page life cycle: at this stage, the Request and Response objects are set. It
also determines the Request type. If the request is an old request or post back, the
IsPostBack property of the page is set to true. The UICulture property of the page is
also set.
Page initialization: In this stage, each control's UniqueID property is set. Master page
and themes are also applied to the page.
Page load: During this phase, if page request is postback, control properties are
loaded with information.
Validation: Validate method of the validation control is called and if it runs
successfully, the IsValidproperty of the page is set to true.
Postback event handling: If the request is a postback (old request), the related event
handler is called. After that the Validate method of all validator controls is called.
Page rendering: At this stage, view state for the page and all controls are saved. The
page calls the Render method for each control and the output of rendering is written to
the OutputStream class of the Page's Response property.
Unload: When everything is over the unload state is performed. At this stage the
requested page has been fully rendered and is ready to terminate. All properties like
Request and Response are unloaded and cleanup is performed.
UNIT-1 Introduction to ASP.NET
1. PreInit –
o PreInit is the first event in page life cycle. It checks the IsPostBack property and determines
whether the page is a postback.
o It sets the themes and master pages, creates dynamic controls, and gets and sets profile property
values.
o This event can be handled by overloading the OnPreInit method or creating a Page_PreInit
handler.
2. Init –
o Init event initializes the control property and the control tree is built. This event can be handled by
overloading the OnInit method or creating a Page_Init handler.
3. InitComplete –
o InitComplete event allows tracking of view state. All the controls turn on view-state tracking.
4. LoadViewState –
o LoadViewState event allows loading view state information into the controls.
5. LoadPostData –
o During this phase, the contents of all the input fields are defined with the <form> tag are
processed.
6. PreLoad –
o PreLoad occurs before the post back data is loaded in the controls.
o This event can be handled by overloading the OnPreLoad method or creating a Page_PreLoad
handler.
7. Load –
o The Load event is raised for the page first and then recursively for all child controls.
o The controls in the control tree are created. This event can be handled by overloading the OnLoad
method or creating a Page_Load handler.
8. LoadComplete –
o The loading process is completed, control event handlers are run, and page validation takes
place.
o This event can be handled by overloading the OnLoadComplete method or creating a
Page_LoadComplete handler
9. PreRender –
UNIT-1 Introduction to ASP.NET
o The PreRender event occurs just before the output is rendered. By handling this event, pages and
controls can perform any updates before the output is rendered.
10. PreRenderComplete –
o As the PreRender event is recursively fired for all child controls, this event ensures the completion
of the pre-rendering phase.
11. SaveStateComplete –
o State of control on the page is saved. Personalization, control state and view state information is
saved.
o The HTML markup is generated. This stage can be handled by overriding the Render method or
creating a Page_Render handler.
12. UnLoad –
o The UnLoad phase is the last phase of the page life cycle. It raises the UnLoad event for all
controls recursively and lastly for the page itself.
o Final cleanup is done and all resources and references, such as database connections, are freed.
o This event can be handled by modifying the OnUnLoad method or creating a Page_UnLoad
handler.