0% found this document useful (0 votes)
15 views37 pages

Unit 1

Unit 1 introduces fundamental concepts of web programming and ASP.NET, detailing the structure and functionality of the World Wide Web, including web servers, clients, and applications. It explains the advantages and disadvantages of web applications, the ASP.NET framework, and its features such as server-side programming and MVC architecture. Additionally, it covers the ASP.NET page life cycle and various file types associated with ASP.NET applications.
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)
15 views37 pages

Unit 1

Unit 1 introduces fundamental concepts of web programming and ASP.NET, detailing the structure and functionality of the World Wide Web, including web servers, clients, and applications. It explains the advantages and disadvantages of web applications, the ASP.NET framework, and its features such as server-side programming and MVC architecture. Additionally, it covers the ASP.NET page life cycle and various file types associated with ASP.NET applications.
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/ 37

Unit 1: Introduction to Asp.

Net

Fundamental concepts of Web Programming

World Wide Web (WWW)


- World Wide Web known as the Web is an information system where documents and other
web resources are identified by Uniform Resource Locators (URL, such as
https://www.sample.com), which may be interlinked by hypertext, and are accessible over
the internet.
- The resources of the WWW are transferred via the Hypertext Transfer Protocol (HTTP) and
may be accessed by users by a software application called a web browser and are published
by a software application called a web server.
- HTTP (Hyper Text Transfer Protocol) Protocol to transfer hypertext requests and information
between server and browser. Various methods available with HTTP such as Get, Post. Put.
Delete, Trace. Head. Options. Connect and so on. It uses standard port 80
- HTTP client (web browser) Ex. Open connection, Request message
- HTTP server (web server) Ex. Response message, Close connection
Website
• A website (also written as web site) is a collection of web pages and related content that is
identified by a common domain name and published on at least one web server. Examples
wikipedia.org, google.com, and amazon.com.
Web Page
• A web page (or Web Pages) is a specific collection of information provided by a website and
displayed to a user in a web browser.
• A website typically consists of many web pages linked together in a logical fashion.
Web Browser
- It is software that runs on the client computer.Ex. Mozilla Firefox, Google Chrome, Internet
Explore etc.
- Technologies used to build Web Application
ASP.Net, JSP, PHP, Servlet, CGI, Perl

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 1


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

Client and Server

- 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).

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 2


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

Why you need a Web Application?


- Compared to desktop applications, web applications are easier to maintain by as they use
the same code in the entire application. There are no compatibility issues.
- Web-Based Apps are Internet-enabled apps that are accessed through the mobile's web
browser. Therefore, you don't require downloading or installing them. You can access
these web applications 24 hours of the day and 365 days a year from any PC
How Web Applications work?

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.

7. The request is handed over to the asp.net service.

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.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 3


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

Advantages of Web Applications


- Zero install - all PCs have a browser
- Reduce business costs - less time spent talking to customers over the phone; eliminate printed
materials; allow users to update their own details.
- Centralized data is secure and easy to backup.
- Quick and easy updates.
- Reach anybody, anywhere in the world.

- Available 24 hours a day, 7 days a week.

- Low spec PCs or smart phones can be used.

- Online training can be completed at user's own time and pace.

- Direct access to latest information.


Disadvantages of Web Applications

- Slower, as run over the internet

- Internet not always 100% available

1.1 What is Asp.Net


ASP is a server-side scripting technology developed by Microsoft. It allows developers to create
dynamic web pages by embedding scripts within HTML code.
Limitation of Asp
- Mix layout (HTML) and logic (scripting code)
- No real state management
- Browser compatibility
- Interpreting ASP code leads to performance loss
- No state sharing access to web forms
- State is lost when IS fails (session data is lost)
- Updates files only when server is down (need to register dll with server)

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 4


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

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.

Key features of ASP.NET include:

- Server-Side Programming: ASP.NET enables developers to write server-side code using


programming languages such as C# (C Sharp) or Visual Basic .NET (VB.NET). This code
runs on the web server and generates dynamic HTML pages that are sent to the client's web
browser.
- Common Language Runtime (CLR): ASP.NET applications are executed within the
Common Language Runtime, a component of the .NET Framework. CLR provides memory
management, security, and other essential services for running the ASP.NET code.
- Web Forms: ASP.NET Web Forms is a feature of the framework that allows developers to
build web applications using a visual drag-and-drop interface. It provides a set of controls,
such as buttons, textboxes, and data grids, which can be easily placed on a web page and
associated with server-side code.
- Model-View-Controller (MVC): ASP.NET MVC is an architectural pattern provided by
ASP.NET. It separates the application logic into three components: the model (data and
business logic), the view (user interface), and the controller (handles user input and
coordinates the model and view). MVC offers more control and flexibility for web
application development.
- ASP.NET Core: ASP.NET Core is the latest version of the framework, which is an open-
source and cross-platform framework. It provides improved performance, modular
architecture, and support for modern web development practices. ASP.NET Core can be used
to build web applications that can run on Windows, macOS, or Linux.
ASP.NET is widely used for building robust and scalable web applications, ranging from small
websites to large enterprise-level systems.

It offers a rich set of features, security enhancements, and integration with other Microsoft
technologies, making it a popular choice among developers.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 5


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

1.1.1 Page Life cycle (IMP)


- When the user request the page, asp.net checks that the class for page is available or not. If it
is present, then it creates the instance of the page class and gives response. But if the class is
not present then it goes under the page life cycle.

- 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.

Phase of Asp.Net Page life cycle (IMP)


- Page request: the page request occurs before the page life cycle starts. It checks that the
page needs to be parsed and compiled or not.
- Page Start: in this phase, several properties such as Response, Request, and Ispostback
are set. Along with, it checks that the request is the postback (the contents of the form are
posted back or itself) request or not.
- Page Initialization: During this phase, the controls are available on the page and its ID
property is set then themes are applied. If the request is the postback request, the postback
data are not loaded and the values of the controls are not restored from the viewstate.
- Page Load: If the request is the postback request, the postback data is loaded and the values
of the controls are not restored from the viewstate.
- Validation: if the validation controls are present on the page then it’s validate () methods is
called, which in turn set IsValid () property of the controls and page.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 6


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

- 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.

Events of Asp.Net page life cycle

- 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.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 7


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

- 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

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 8


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

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

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 9


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

1.1.2 Asp.net files types and subdirectory.

File type Location Description

Typically a Global.asax file that represents the


application class and contains optional methods
.asax(imp) Application root.
(event handlers) that runs at various points in the
application life cycle.
A Web user control file that defines a custom
Application root or a
.ascx(imp) functionality that you can add to
subdirectory.
any ASP.NET Web Forms page.
Application root or a A handler file that is invoked in response to a
.ashx
subdirectory. Web request in order to generate dynamic content.
An XML Web services file that contains classes
Application root or a
.asmx(imp) and methods that can be invoked by other Web
subdirectory.
applications.
Application root or a An ASP.NET Web Forms page that can contain
.aspx(imp)
subdirectory. Web controls and presentation and business logic.

App_Browsers A browser definition file that identifies the


.browser(imp)
subdirectory. features of an individual browser.
Application root or a
.cd A class diagram file.
subdirectory.
A precompiled stub files that point to an assembly
that represents a compiled Web site file. When
.compile Bin subdirectory. you precompile a Web site project, executable file
types (.aspx, ascx, .master, and theme files) are
compiled and put in the Bin subdirectory.
.config(imp) Application root or a A configuration file contains XML elements that

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 10


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

subdirectory. represent settings for ASP.NET features.


App_Code subdirectory,
or in the case of a code- Source code files (.cs or .vb files) that define code
behind file for that can be shared between pages, such as code for
.cs, .vb
an ASP.NET page, in the custom classes, business logic, HTTP modules,
same directory as the Web and HTTP handlers.
page.
Visual Studio project A project file for a Visual Studio Web-application
.csproj, .vbproj
directory. project.
App_WebReferences An XML Web services discovery file that is used
.disco, .vsdisco
subdirectory. to help locate Web services.
A compiled class library files (assembly). In a
Web site project, instead of placing compiled
.dll Bin subdirectory. assemblies in the Bin subdirectory, you can put
source code for classes in the App_Code
subdirectory.
Application root or A master page that defines the layout for other
.master(imp)
subdirectory. Web pages in the application.
.mdb, .ldb App_Data subdirectory. An Access database file.
.mdf(imp) App_Data subdirectory. A SQL Server Express database file.
App_GlobalResources or
.resources, A resource file that contains resource strings that
App_LocalResources
.resx refer to images, localizable text, or other data.
subdirectory.
A sitemap file that defines the logical structure of
the Web application. ASP.NET includes a default
.sitemap(imp) Application root.
sitemap provider that uses sitemap files to display
a navigational control in a Web page.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 11


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

App_Themes A skin file that contains property settings to apply


.skin(imp)
subdirectory. to Web controls for consistent formatting.

Visual Studio project


.sln(imp) A solution file for a Visual Studio project..
directory.

Application root or a
.soap A SOAP extension file.
subdirectory.

1.2 The .Net Framework


- The .NET Framework is a software framework developed by Microsoft that mainly runs
on Microsoft Windows. It provides a large library of pre-built code and a runtime
environment for creating and running applications. It supports multiple programming
languages and allows developers to build a wide range of applications, including desktop
applications, web applications, and much more.

Figure 1 : Narrow view of .Net framework

Architecture of .Net Framework

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 12


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

- The .Net framework consists core components Common Language specification,


Common Language Runtime, Base class library. It also supports different types of
languages for programming. Figure 2 provides an illusion of the .Net Framework.

Figure 2: Components of .Net framework

The .NET Framework consists of:

(1) Common Language Runtime (CLR)


- It is the execution environment of the .NET Framework.It is the heart and engine of .net
framework. When a .NET application is compiled, it generates an intermediate language
code called Common Intermediate Language (CIL) or Microsoft Intermediate Language
(MSIL) which is language independent. When the MISL code is executed, the CLR
compiles it into machine code (Native Code) and managing the execution of the resulting
program. The code which runs under the CLR is called as Managed Code. It provides
various services, including automatic memory management, exception handling, security,
and type safety.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 13


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

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++.

Figure 3: Program execution under CLR

Microsoft Intermediate Language

- Microsoft Intermediate Language (MSIL) also known as Intermediate Language (IL) or


Common Intermediate Language (CIL). It is also called Manage Code. While your
program is running, the.NET Compiler will generate MSIL, and the Just in Time (JIT)
compiler will translate your Intermediate Language into machine code (Native Code). It
is a CPU-independent set of instructions that can be efficiently converted to the native
code. When a .NET compiler produces MSIL, it also produces Metadata (Data about
Data). Metadata is nothing but a description of every namespace, class, method, Property

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 14


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

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:

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 15


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

- UDDI (Universal Discovery and Description Integration)


o WSDL (Web services Description Language)
o SOAP (Simple Object Access Protocol)
o XML (Extensible Markup Language)
o HTTP (Hypertext Transfer Protocol)
o SMTP (Simple Mail Transfer Protocol)

(6) The Common Language Specification (CLS)

- 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:

- Establishes a framework that helps enable cross-language integration, type safety,


and high-performance code execution. Provides an object-oriented model that
supports the complete implementation of many programming languages. Defines
rules that languages must follow, which helps ensure that objects written in
different languages can interact with each other.
Some Concept which are important in .Net

- 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.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 16


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

Figure 4: Components of Assembly

- 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:

- It is difficult to debugging when program is very large.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 17


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

- It is difficult to find the error.

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).

1.4 Common Language Runtime


- .NET Framework provides runtime environment called Common Language Runtime
(CLR). It is the heart of .net framework. It is the engine that compiles and run the
application. It uses MSIL code which is language independent for execution. The MSIL
code is translated by JIT compiler.
- It provides an environment to run all the .NET Programs. The code which runs under the
CLR is called as Managed Code. Programmers need not to worry on managing the
memory if the programs are running under the CLR as it provides memory management
and thread management.
- Execution in CLR

Figure 5: Program execution flow under CLR

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 18


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

- 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.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 19


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

1.5 Object Oriented Concepts


- All languages those supports the concepts of OOP they are considered as OOP
programming language.
- All OOP based languages supports the following concepts.
- Class and Object
- Abstraction and Encapsulation
- Constructor and Destructor
- Inheritance
- Polymorphism
Class
- Class is a group of methods and variables where methods are known as Member
function and variables are known as Data Member.
- In vb.net class is created using Class Keyword and completed with End Class.
- Once class is created you can created any number of objects.
Syntax:
[accessmodifier][Shadows][MustInherit|NotInheritable]

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.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 20


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

- 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

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

- Add windows form name frmclass.vb and write down the following code in btnclass
click event.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 21


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

Private Sub btnclass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btnclass.Click
Dim obj As New Class1 ‘object is created
obj.getdata(10, 20) ‘method is called
obj.disp()
MsgBox("the sum of two no is " & obj.sum())
End Sub
Object

- 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:

Private Sub btnclass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btnclass.Click
Dim obj As New Class1 ‘object is created
obj.getdata(10, 20) ‘method is called
obj.disp()
MsgBox("the sum of two no is " & obj.sum())

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

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)

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 23


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

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

Add Class file and give name ClsConstuctor

Public Class ClsConstuctor


Dim i As Integer
Dim n As Integer
'Constructor without arguments
Sub New()
MsgBox("I am Default Constuctor")
End Sub
'Constructor with arguments
Sub New(ByVal i As Integer)
n=i
MsgBox("I am paramiterized Constuctor")
MsgBox(n)
End Sub
Protected Overrides Sub finalize()
Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 24
Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

n=0
MsgBox("I m Desctuctor")
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 x As New ClsConstuctor
Dim y As New ClsConstuctor(10)
End Sub
- How to call Base Class Constructor
- It can be called using MyBase keyword.
- It cannot be used to access private members of class.
- It refers to the immediate base class and its inherited members
- Example:

Public Class ClsBase


Private x, y As Integer
Sub New()
x=0
y=0
End Sub
Sub New (ByVal a As Integer, ByVal b As Integer)
x=a
y=b
End Sub
End Class

Public Class clsderive


Inherits ClsBase

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 25


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

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

- It is a special function which is called automatically when a class is destroyed.


- A destructor is also known as finalizer. It is the last method run by class
- Within a destructor we can place code to clean up the object after it is used ,which might
include decrement counters releasing resources
- It cannot be overloaded.
- Example:

Protected Overrides Sub finalize()


n=0
MsgBox("I m Desctuctor")
End Sub

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 26


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

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

Public Class ClsBase ‘Base Class


Protected a As Integer = 40
Sub disp()
MsgBox("I am Base Class")
End Sub
End Class

Public Class clsderive ‘Derive Class


Inherits ClsBase
Dim b As Integer = 20

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 27


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

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

Public NotInheritable Class clsA

End Class

Public Class ClsB


Inherits clsA ‘ClsB cannot inherite from class ClsA because ‘ClsA is declared as
NotInheritable

End Class

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 28


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

MustInherit (Abstract Class)

- MustInherit Keyword is used to create Abstract Class.


- It specifies that class is intended as a base class.
- It provides Skelton to the derived class. it has no actual code.
- It is not used to create an object.
- If our class contains at least one MustOverride method then our class should be declare as
MustInherit class.
- Methods written in Abstract class as MustOverride are automatically appear in the derived
class.
- Mustoverride methods must be declared in MustInherite Class.
- No other statements are allowed and especially there is No End Sub or End Function.
- Example

Add Class file and give name clsAbs1

Public MustInherit Class clsAbs1


MustOverride Sub add(ByVal a As Integer, ByVal b As Integer)
MustOverride Sub div(ByVal a As Integer, ByVal b As Integer)
End Class

Add another Class file and give name clstemp

Public Class clstemp


Inherits clsAbs1
Public Overrides Sub add(ByVal a As Integer, ByVal b As Integer)
MsgBox(a + b)

End Sub

Public Overrides Sub div(ByVal a As Integer, ByVal b As Integer)


Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 29
Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

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

- It means “one name, multiple forms


- There are two types of it (1) Design time (2)Run time
- Design time polymorphism is achieved by function overloading
- Run time polymorphism is achieved by function overriding
- Function overloading means we can declare more than one functions with the same name
but arguments are different.
- Example
Add Class file and write this code (it is the example of function overloading)
Public Class Clsmath
Function add(ByVal a As Integer)
Return MsgBox(a)
End Function
Function add(ByVal a As Integer, ByVal b As Integer)
Return MsgBox(a + b)
End Function
Function add(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer)
Return MsgBox(a + b + c)
End Function
Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 30
Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

End Class

Write this code on btnpoly_click event

Private Sub btnpoly_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnpoly.Click
Dim obj As New Clsmath
obj.add(5)
obj.add(5, 5)
obj.add(10, 20, 30)
End Sub

Run time polymorphism (function overriding)

- 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

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 31


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

Public Class Clsoverridable


Public Class base
Overridable Sub disp()
MsgBox("Base class")
End Sub
End Class
Public Class clsderived
Inherits base
Public Overrides Sub disp()
MyBase.disp()
MsgBox("Derived Class")
End Sub
End Class
End Class
Write this code in btnoverriding_click Event

Private Sub btnoverriding_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnoverriding.Click
Dim obj As New Clsoverridable.clsderived
obj.disp()
End Sub

Interface

Why interface used?


We cannot inherit more than one class in vb.net. If we wants to inherit then? Use interface

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 32


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

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

Add interface in your project

Public Interface Interface1


Sub hi()
End Interface
Add another interface in your project
Public Interface Interface2
Sub hello()
End Interface

Add Class File in your project

Public Class ClssInterface


Implements Interface1, Interface2

Public Sub hi() Implements Interface1.hi


MsgBox("Hi i m interface 1")

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 33


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

End Sub

Public Sub hello() Implements Interface2.hello


MsgBox("Hello i m interface 2")
End Sub
End Class

Write down this code in btninterface_click Event

Private Sub btninterface_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btninterface.Click
Dim obj As New ClssInterface
obj.hi()
obj.hello()
End Sub

1.6 Event Driven Programming


- Event Driven Programming In which the flow of program execution in depends on the event
is called event driven programming. for example user action such as a mouse click, key
press, or a message from the operating system or another program.
- It does not follow the predefine path for execution.
Properties mean characteristics of anything. Example Laptop, Mobile, Car Etc.
- Events means an interaction between the user and application or between the application and
the system.
- Methods are nothing but function or procedure. Doing something is method.

1.7 Exercise
Solve the following multiple-choice questions.

1. What is the full form of MSIL?

A. Many Intermediate Language B. Microsoft Intermediate Language

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 34


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

C. Microsoft Intermediate Long D. Microsoft Internal Language

2. .Net framework consists

A. MSIL B. CLR

C. FCL D. All of these

3. The code which is run under CLR known as ________

A. Manage Code B. Unmanage Code

C. Garbage Code D. None of these

6 The Data about data is known as _______________

A. Metadata B. Assembly

C. MSIL D. Manifest

7 _____________is known as heart of .net framework.

A. MSIL B. CLS

C. CTS D. CLR

Answers

1.A 2.A 3.B 4.B 5.C 6.B 7.A

Answer the following short questions:

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.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 35


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

4. Define .Net framework?


5. Define JIT.
6. What do you mean by Native Code?
7. What is manage code?
8. What do you mean by Assembly, Metadata, and Manifest?
9. What is Class and object?
10. What is Data Abstraction?
11. What is Data encapsulation?
12. What is inheritance?
13. What is Polymorphism?
14. List out types of polymorphism.
15. What is constructor and destructor?
16. How to call base class constructor?
17. Which keyword is used to create abstract class?
18. What do you mean by function overloading?
19. What do you mean by function overriding?
20. Why interface is used? Justify your answer.
21. Which keyword is used for implementing interface?
22. What is event driven programming?
23. What do you mean by property?
24. What do you mean by method?
25. What do you mean by event?

Answer the following long questions:

1. Explain Asp.Net page life cycle.


2. Mention Asp.Net files and directories.
3. Explain .Net Architecture.
4. Explain Common Language Runtime.
5. Discuss Common Type Specification.
6. What is class explain with example.
7. Explain inheritance in detail.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 36


Sutex bank college of computer applications and science.
Unit 1: Introduction to Asp.Net

8. List out object oriented concepts. Explain any of two concepts.


9. Explain constructor and destructor?
10. Explain interface in detail.
11. Write a note on abstract class.

Asst.Prof. Nayna N Mistry(M.C.A. NET,GSET) Page 37


Sutex bank college of computer applications and science.

You might also like