Unit 1
Unit 1
Net
- To access information stored in the form of web pages, user (clients) must connect to as web
server.
- Web Server: The Machine where the web site stored.
- When you send a request for a web page by entering a web site address (URL), this request
is sent to a web server. The web server then sends the web page to your browser.
- Web clients: computer (or any device) that offer the facility to read information stored in the
web pages.
Web Application
- A web application is a software or program which is accessible using any web browser. Its
frontend is usually created using languages like HTML, CSS, JavaScript, which are
supported by major browsers.
Virtual Directory
- A directory name that you specify in IIS (Internet Information Services - web server
software) map to physical directory on a local server’s hard drive or a directory on another
server (remote server).
Web applications work quite different from regular windows applications. There are several
computers involved when you view a web page.
1. You type the web page address (URL) in a browser. For example, consider the current
page http://www.testing.com/test.aspx.
2. This URL has 3 parts:
The protocol – http:
The IP address name – www.aspsamples.com
The file name – test.aspx
3. Browser communicates with a computer in internet called ‘Domain Name Server’ to
find out the IP Address of the server (Ex: www.testing.com).
4. Browser established a connection to the web server at that IP Address.
5. Server composes a ‘Request’ for the specified URL and sends the request to the web
server to which it has established a connection.
6. The web server identifies the type of the page requested. If it is an asp.net web page, then
browser knows that needs some processing by the asp.net service running as part of the
web server.
8. The asp.net service processes the asp.net page and generates the html output.
9. Web server sends the requested page to the browser.
10. When a response is received by the browser, it displays the web page to the user who
typed the URL.
What is Asp.Net?
- ASP.NET is a web development framework developed by Microsoft. It is a successor to the
earlier Active Server Pages (ASP) technology. ASP.NET allows developers to build dynamic
web applications and websites using server-side programming.
It offers a rich set of features, security enhancements, and integration with other Microsoft
technologies, making it a popular choice among developers.
- When the request comes the ASPX page is given for parsing to the ASPX engine. Then from
that parsed page and the code behind class, a combined page class is generated and it is
compiled. At last the instance of the class is created and rendered for the user. In short, web
forms are in the form of page class.
- Postback Event handling: if the event handlers of the PostBack are need to be called, and
then they are called during this phase.
- Rendering: Prior to this phase, the view state for page and controls are saved, during
rendering phase Render () method of the controls and page is called which gives the output
to the OutPutStream of the Response Property.(Ready to load)
o It occurs when all the response information has been sent back to the user. It also
stores all the information that is being sent.
- Unload when there is a need to dispose (close) the page as it might not be further needed. A
request and Response property of the page is also unloaded.
- PreInit: it occurs before the page is initialized. The Page_PreInit event allows you to
perform tasks such as dynamically creating or modifying controls before the view state is
loaded and before the postback data is processed. Use this event for the following.
- Check the IsPostBack property to determine whether this is the first time the page is
being processed.
- Create or recreate dynamically controls.
- Set a master page, Theme Property dynamically.
- Read or set profile property (server side state mgt technique) values.
- Init: This event occurs when the page is initialized. You can use this event to initialize
controls, set up database connections, or perform other initialization tasks.
- PreLoad: it occurs before the page_load event. It provides a useful opportunity to perform
additional tasks or data operations before the page is loaded with data and events are
processed.
- Load: This event occurs when the page is loaded into memory. It is a common place to put
code that binds data to controls or performs other tasks that should occur on every page load.
- Control events: These events occur when a user interacts with controls on the page, such
as button clicks or dropdown list selections. Examples of these events include Button_Click,
SelectedIndexChanged, etc.
- PreRender: This event occurs just before the page is rendered to the client. You can use this
event to make final modifications to the page or its controls.
- Render: This event occurs when the page is rendered to the client. It is the last event in the
page life cycle and usually not used for writing custom code.
- Unload: This event occurs when the page is unloaded from memory. It is used to release
resources or perform cleanup tasks.
Example:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Init
Response.Write("2")
End Sub
Protected Sub Page_InitComplete(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.InitComplete
Response.Write("3")
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
Response.Write("5")
End Sub
Protected Sub btnsave_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles btnsave.Click
End Sub
Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.LoadComplete
Response.Write("6")
End Sub
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.PreInit
Response.Write("1")
End Sub
Protected Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.PreLoad
Response.Write("4")
End Sub
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.PreRender
Response.Write("7")
End Sub
Application root or a
.soap A SOAP extension file.
subdirectory.
Execution in CLR
- The provided figure illustrates the programming execution flow when you develop
programs in various programming languages, such as Vb, C#, and C++.
etc. The MSIL and Metadata are contained in a portable executable (PE) file. The MSIL
includes instructions for loading, storing, initializing, and calling methods on objects.
(2) Base Class Libraries (BCL)
- It is also known as framework class library (FCL). It is the object-oriented collection of
reusable types. It is a Library of prepackaged functionality and Applications. It provides
classes which encapsulate a number of common functions, including file reading &
writing, Graphics rendering, database interaction and XML document manipulation.
(3) ADO.Net and XML
- It is also known as data access layer. With the help of this layer, we can access relational
databases. It works with XML and provides the disconnected Data Model. It is a part of
BCL.it consists of Data Provider Data Set.
(4) Window Forms
- It is also known as Win Forms. It is used to create GUI for windows desktop application.
it also provides integrated and unified way of developing GUI. It has a rich variety of
windows controls and user interface support like Textbox, Button, Checkbox, Etc. Using
visual Studio.NET, we can simply design the GUI by dragging the controls on a form.
(5) Web Forms & web Services
Web Forms
- It provides a tool for web application. It is a part of ASP. Net. It is the forms engine that
provides Browser –based user interface. Web Forms are similar to Windows Forms in
that they provide properties, methods, and events for the controls that are placed onto
them. However, these UI elements render themselves in the appropriate markup language
required by the request, e.g. HTML. If you use Microsoft Visual Studio® .NET, you will
also get the familiar drag-and-drop interface used to create your UI for your Web
application.
Web Services
- Web services are the applications that run on a web server and communicate with other
application. It uses a series of XML based communicating protocols that respond to
different requests.
- The protocols on which web services are built summarized below:
- It is a set of rules and constraints that all language must follow which want to be
compatible with .NET framework. It is used to support the theme of .NET i.e. unification
and interoperability (The ability of computer systems or software to exchange and make
use of information). That means, if we want the code which we write in a language to be
used by programs in other language (cross-language integration) then it should hold on to
the CLS.Thus the CLS describes a set of features that are common different languages.
CLS performs the following functions:
- Assembly All of the managed code that runs in .NET must be contained in an assembly.
Logically, the assembly is referenced as one EXE or DLL file. Physically, it may consist
of a collection of one or more files that contain code or resources such as images or XML
data. An assembly is created when a .NET compatible compiler converts a file containing
source code into a DLL or EXE file.
- Manifest. Each assembly must have one file that contains a manifest. The manifest is a
set of tables containing metadata that lists the names of all files in the assembly,
references to external assemblies, and information such as name and version that identify
the assembly.
- Metadata When a compiler produces Microsoft Intermediate Language (MSIL), it also
produces Metadata (Data about Data). Metadata is nothing but a description of every
namespace, class, method, Property etc. The Microsoft Intermediate Language (MSIL)
and Metadata are contained in a portable executable (PE) file. It allows loading and
locating code, enforcing code security, generating native code, and providing reflection at
runtime.
1.3 Compile Code
When you write ASP.NET code, you do so in human-readable text. Before ASP.NET can
run your code, it has to convert it into something that the computer can understand and
execute. The process of converting code from what a programmer types into what a
computer can actually execute is called compilation.
1.3.1 Inline Code and Code behind
Inline code: It will provide mix layout means both designing and coding will be done in a
single.aspx file using <Script> tag.
Disadvantage:
Code behind: It will provide separate layout for designing and coding. Here two separate
file is created one for designing (.aspx) and another for coding (.aspx.vb, .aspx.c depending
on language).
- When the .NET program is compiled, the output of the compiler is not an executable file
but a file that constraints a special type of code is called Microsoft intermediate language,
which is a low-level set of instructions understand by CLR.
- The MSIL defines a set of portable instructions that are CPU independence.
- It is the functionality of the CLR to translate this MSIL into native code when the
program is executed, making the program to run in any environment for which the CLR
is implemented. And that’s how the .NET framework achieves Portability (run in any
environment). This MSIL is converts into Native code using JIT (Just in Time) compiler.
Purpose of CLR
- Thread Support: Threads are managed under the Common Language Runtime. Threading
means parallel code execution. Threads are basically light weight processes responsible
for multi-tasking within a single application.
- COM Marshaler: It allows the communication between the application and COM objects.
- Type Checker: It will verify types used in the application with CTS or CLS standards
supported by CLR, this provides type safety.
- Exception Manager: It handles all the runtime exceptions (Error) thrown by application
- Security Engine: It enforces security permissions at code level security, folder level
security, and machine level security using Dot Net Framework setting and tools provided
by Dot Net.
- Debug Engine: CLR allows us to perform debugging an application during runtime.
- MSIL: Microsoft Intermediate Language is considered to be the lowest form of human
readable language. It is CPU independent and includes instructions of how to load, store,
initialize objects. JIT converts this MSIL into native code which is independent on the
CPU.
- Code Manager: CLR manages code. When we compile a .NET application you don't
generate code that can actually execute on your machine. You actually generate
Microsoft Intermediate Language (MSIL or IL). All .NET code is IL code. IL code is also
called Managed Code, because the .NET Common Language Runtime manages it.
- Garbage Collector: It handles automatic memory management and it will release memory
of unused objects in an application, this provides automatic memory management.
- Class Loader: as and when needed. It loads the class into the system memory.
Class <Classname>
[Inherits classname]
[Implements interfacenames]
[statements]
End Class
where
- Accessmodifier defines the access levels of the class; it has values as - Public, Protected,
Friend, Protected Friend and Private. Optional.
- Shadows indicate that the variable re-declares and hides an identically named element, or
set of overloaded elements, in a base class. Optional.
- MustInherit specifies that the class can be used only as a base class and that you cannot
create an object directly from it, i.e., an abstract class. Optional.
- NotInheritable specifies that the class cannot be used as a base class.
- Inherits specifies the base class it is inheriting from.
- Implements specify the interfaces the class is inheriting from.
Example
- Add new class file to the project and give proper name (Class1.vb). The extension of the
class is .vb
- Write down the following code in Class1.vb File
- Add windows form name frmclass.vb and write down the following code in btnclass
click event.
- It is runtime entity.
- It is member of class which is able to access methods and variables of class which has
been declared in Public Mode.
- In vb.net ,it can be created as follows:
Syntax:
<object> As New <Class Name>
Example:
End Sub
Abstraction
- It refers to the act of representing essentials features without including the background details
or explanations.
- It defines way to abstract or hide your data and members from outside class.
- Classes use the concept of Abstraction.
- When we define a classes then different accessibility mode define the access level of
variables and methods. They are Public, Private, Protected.
Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 22
Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net
- Example:
Public Class Class1 'class name
Dim a, b As Integer
'Class Method
Sub getdata(ByVal i As Integer, ByVal j As Integer)
a=i
b=j
End Sub
Sub disp() 'class method
MsgBox("a==" & a & "b==" & b)
End Sub
Function sum() As Integer 'function
Return a + b
End Function
End Class
Encapsulation
- It is a process to bind data and methods in a unit called class. When we define class that
process itself define the concept of Encapsulation.
- It can protect your data from accidental corruption.
- Rather than defining the data in the form of public, we can declare those fields as private.
- Example
End Sub
Function sum() As Integer 'function
Return a + b
End Function
End Class
Constructor
- It is a special member function which is used to initialize the object of its class.
- It is automatically called when object is created.
- In vb.net, The name of constructor is NEW()
- It can be overloaded.
- There are 2 types of constructor such as constructor with arguments and without
arguments.
- Example
n=0
MsgBox("I m Desctuctor")
End Sub
End Class
Add windows form and write down the following code in btnconstructor click event.
Private z As Integer
Sub New()
MyBase.New()
z=0
End Sub
Sub New(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer)
MyBase.New(a, b)
z=c
MsgBox(a & b & c)
End Sub
End Class
- Add windows form and write down the following code in btnconstructor click event.
Private Sub btnConstructor_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnConstructor.Click
Dim obj As New clsderive
Dim obj1 As New clsderive(4, 6, 7)
End Sub
Destructor
Inheritance
- It is a process of creating a new class called derives class from the existing class called Base
Class.
- The existing class is known as parent, base, super class.
- The new class is known as child, derive, sub class.
- It is also known as code reusability.
- It can be created by using inherits keyword.
- A derive class obtain all of the methods, properties, and events of the base class.
- There are 3 modifier related with inheritance.
- Inherits
- NotInheritable
- MustInherit(Abstract Class)
- Syntax
Class <Class Name>
[inherits] Base Class Name
Statements
End Class
- Example
- Add class file name clsbase and write down the following code
Sub show()
MsgBox("value from Base Class=" & a)
MsgBox("value from Derive Class=" & b)
MsgBox("I am Derived Class Method")
End Sub
End Class
- Add windows form and write down the following code in btninheritance click event
Private Sub btninheritance_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btninheritance.Click
Dim x As New clsderive
x.disp() ‘Base Class Method
x.show() ‘Base + derive Class’
End Sub
NotInheritable
- It is known as seal class. If we write NotInheritable keyword in class then no other class can
be derived from this class.
- It gives surety that your class is not become parent of any class.
• Example
Create class clsA as NotInheritable and try to derive it in clsB
End Class
End Class
End Sub
MsgBox(a / b)
End Sub
End Class
- Add windows form and write down the following code in btnabstactclass_Click event
Private Sub btnabstactclass_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnabstactclass.Click
Dim obj As New clstemp
obj.add(10, 20)
obj.div(20, 10)
End Sub
Polymorphism
End Class
- Function overriding means when we declare more than one function with same name but
in different class and the relationship between class is parent -child
- The overriding concept achieve only in inheritance.
- Derive class inherits methods from its base class
- If an inherited property or method needs to behave differently in the derived class.
- Overridable keyword is used to mark a function as override. We can redefine
overridable methods in derived class
- The overrides keyword is used to mark that a function is overriding some base class
function.
- The overrides keyword overrides an overridable property or method defined in the base
class
- Example
Interface
Interface
- Interfaces like classes define a set of properties, methods and events. But unlike classes, an
interface does not contain any implementation code
- Interface represents “Has a” relationship
- Classes which implements interface they write the coding in the interface’s method
- We can implements multiple interface
- If we want to use interface then we need to write” Implements” keyword
- Syntax
Public Interface iface1
….logic
End Interface
- Example
End Sub
1.7 Exercise
Solve the following multiple-choice questions.
A. MSIL B. CLR
A. Metadata B. Assembly
C. MSIL D. Manifest
A. MSIL B. CLS
C. CTS D. CLR
Answers
1. Give the Full Form of: CLR, MSIL, JIT, CLS, CTS, FCL, and BCL.
2. Give the alternative name of MSIL?
3. Define MSIL and CLR.