UNIT 1 Introduction to ASP.Net By: Hitesh Santani
UNIT 1 Introduction to ASP.Net
By: Hitesh Santani
What is Web?
By: Hitesh Santani
• Web is a large and public network with which we can access the information from anywhere in the world.
• Generally, people call it The Internet.• The information which is available on web, is
in many forms like text, images, audio and video.
• This information is embedded into web pages through which we can access them.
What is a Website?
By: Hitesh Santani
A website is a collection of web pages. These web pages are made up of HTML, CSS,
Javascript, jQuery and a server side programming language like ASP.Net, PHP, JSP, Java Servlets etc.
A website can only be used using a web browser.
Example: www.gmail.co.in
How Internet works?
By: Hitesh Santani
Client
Request
HTTP REQU
EST
INTERNET
HTTP Request REQUEST
RESPONSEHTTP Response
HTTP Response
Response
Server Database
How Internet works?
By: Hitesh Santani
• A client is a user who wishes to use the website for the info.• A server is a machine where the actual website is stored.
This server is connected with the internet.• The clients use a browser or any other HTTP supported
software to communicate with the server through internet.• HTTP (Hyper Text Transfer Protocol) is a protocol which
governs the rules related to Hyper Text Transmission in between two machines on a network.
• Whenever, we type in a URL into the address bar of a browser, an HTTP Request is generated and is sent to the server.
• The server then processes this request and replays with an HTTP Response which contains the HTML output.
What is .Net?
By: Hitesh Santani
First of all, .Net is not a language but it is a framework.
It is a software platform with which you can create windows and web applications.
It provides you all the required features which can make your work of developing applications easy.
Architecture of .Net
By: Hitesh Santani
VB C#
Common Language Specification (CLS)
ASP .NetWeb
ServicesWeb
Forms
WindowsForms
ADO .Net and XML
Base Class Library (BCL) or Framework Class Library (FCL)
Common Language Runtime
Operating System
C++ J# ……Language Compilers
.Net Framework
Language Compilers
By: Hitesh Santani
There are compilers available separately for each and every language individually.
The task being assigned to the compilers for the .Net framework, is to convert the source code of the programs into MSIL Code.
Compilation Process in .Net
By: Hitesh Santani
.vb .cs ……
VBCompiler
C#Compiler ……
Common Language Runtime (CLR)
Operating System
Sour
ce
Code
Sour
ce
Code
Sour
ce
Code
Nati
ve
Code
MSIL Code
MSIL Code
By: Hitesh Santani
• MSIL Code stands for Microsoft Intermediate Language Code which is also called IL Code.
• This MSIL Code can not be executed by the hardware.
• MSIL Code solves a major problem i.e. creating a separate compiler for each of the languages to convert the source code to a particular device type.
• That’s why it is given to the CLR to generate Native Code (Machine Code) from it.
• This Native Code can be executed by the hardware.
Common Language Specification (CLS)
By: Hitesh Santani
Common Language Specification (CLS) is a set of rules.
These rules must be followed by any language which wants to be .Net compliant and wants to run it’s programs in CLR.
CLS is a subset of Common Type System (CTS).
Common Type System (CTS)
By: Hitesh Santani
• Common Type System (CTS) allows program written in different programming languages to share information easily.
• This means that we can use a class which is written in C# in VB.Net.
• Languages must agree on these concepts before they can integrate with one another.
• CTS defines the rules which must be followed by the languages to ensure smooth data sharing between them.
• Thus, CTS provides Cross Language Integration or Language Interoperability.
• CTS supports two categories of types: Value types and Reference types.
By: Hitesh Santani
Value types: Which stores the data directly in stack. In built data types come under this category.
Reference types: Which stores the reference or address instead of
storing the data directly. This type of data is stored in heap instead of
stack. Objects are example of this category.
Framework Class Library (FCL)
By: Hitesh Santani
• Framework Class Library (FCL) which is also known as Base Class Library (BCL), is a set of readily available classes.
• It is the in built set of classes which we can directly use on the fly after importing them into the programs.
• These are like the header files which we used to have in C or C++.
• This class library consists of thousands of classes which are categorized into namespaces so that we can remember them easily.
Namespaces
By: Hitesh Santani
• A namespace is a logical collection/grouping of classes.• It helps us out to categorize the library classes in
according to their purpose.• Because of the namespaces, we do not have to
remember names of each and every class.• We just need to remember the name of the namespace
to which the class belongs.• A namespace is just a logical container for the library
classes.• Namespaces can be used to differentiate two different
classes with the same name using a Fully Qualified Name. A Fully Qualified Name is a combination of the class name and the namespace’s name to which the class belongs.
• The topmost namespace in the .Net framework is System. The rest of the namespaces are a part of the System namespace.
Common Language Runtime (CLR)
By: Hitesh Santani
• CLR is one of the main components of .Net.• It’s the execution engine and environment of
the framework.• It stays in between the .Net framework and
the underlying Operating System.• It loads and executes the code.• It provides all the services which the program
may need at run-time.• Every language that wants it’s programs to
run in CLR, must obey the rules being imposed by CLR.
Compiled Code
By: Hitesh Santani
In order to serve the request given by the user, ASP.Net must first compile the code. We can write the ASP.Net code in any of the languages supported by .Net framework.
When we compile the code, it is translated into MSIL which is language-independent.
Then this MSIL is converted into machine-specific instructions.
Benefits of Compiled Code
By: Hitesh Santani
• Stability: When the code is compiled, it is checked for syntax error, type safety etc so that many errors can be eliminated from the later stage.
• Performance: The execution of the compiled code is faster then the scripts such as VBScript.
• Security: Compiled code is difficult to read. So no one can convert the compiled code back into the source code.
• Interoperability: We are able to use assemblies written in different languages as MSIL supports any .Net languages.
Inline Code (In-Page Code)
By: Hitesh Santani
Traditional developers were using this approach.
Client-side and Server-side code is intermixed into a single page.
Becomes very difficult to maintain the events and event handlers in a large single page.
Its written in the <script> tag.
Code Behind
By: Hitesh Santani
• Separate files are maintained for Client-side and Server-side code.
• One file contains HTML which is the .aspx file.• The other file contains the server-side code
which is called Code Behind file. It can be either .vb or .cs.
• Separates the design layout and the coding part.
• At the time of compilation, both files are combined and one class is generated which is used to serve the user requests.
Object Oriented Concepts
By: Hitesh Santani
Class Fields Properties Methods Events
Objects Constructors Destructors Encapsulation
Inheritance Abstraction
Abstract Class Interface Polymorphism Method Overriding Partial Classes
Class
By: Hitesh Santani
The class is a template through which we can create an object.
In .Net, it contains fields, properties, methods (procedures and functions) and events.
Syntax:[Access Modifier] [Shadows] [MustInherit|NotInheritable] Class
<name> [Implements <interfacename>]Statements
End Class
Fields
By: Hitesh Santani
They are the variables in the class. They can be read or set directly. They store the actual data which is being
given to an object. Example:
Public Class MyClassPublic x As Integer
End Class
Properties
By: Hitesh Santani
• Properties are retrieved and set like fields.• They are implemented using Property Get and Property
Set procedures which provide more control on how values are set or returned.
• Example:Public Class MyClass
Private Name As StringPublic Property FullName() As String
GetReturn Name
End GetSet(ByVal Value As String)
Name = ValueEnd Set
End PropertyEnd Class
Methods
By: Hitesh Santani
• Methods represent the object’s built-in procedures.• For example, a class named Employee may have
methods named CalculateSalary and CalculateLeaves.
• We can defined methods by adding procedures and functions to the class.
• Example:Public Class Employee
Public Sub CalculateSalary()Write(“-------”)End SubPublic Sub CalculateLeaves()Write(“-------”)End Sub
End Class
Objects
By: Hitesh Santani
They are the basic runtime entities. They are the variables of the class.
It is said to be the instance of the class. Example:
Dim obj as MyClass
Constructor
By: Hitesh Santani
They are the special procedures that are invoked automatically when an object of a class is created.
Example:Public Sub New(ByVal newValue as Integer)
value = newValueEnd Sub
Destructor
By: Hitesh Santani
• We know how to create constructor, but what about destructor?
• It is also executed automatically when an object is about to be destroyed.
• We can place code to clean up the reserved resources in a destructor.
• In VB.Net, we can use the Finalize method for this purpose. The Finalize method is called automatically when an object is marked as unusable and is to be destroyed.
• Example:Public Class MyClass
Protected Overrides Sub Finalize()StatementsEnd Sub
End Class
Encapsulation
By: Hitesh Santani
• The process of combining data members and methods in a single unit is called Encapsulation.
• When using Data Encapsulation, data is not accessed directly, it is only accessible through the functions available within the class.
• Data Encapsulation enables the important concept of Data Hiding.
• Protecting data from unauthorized access is called Data Hiding.
Inheritance
By: Hitesh Santani
• It is the process by which object of one class acquires the properties (members) of another class.
• It’s the process of forming a new class from an existing class.
• The existing class is called a parent/super/base class.
• The new class is called child/sub/derived class.• It is important because it supports hierarchical
classification and code reusability. • We can add new features to a class without even
touching it by deriving a new class.• To inherit the class, Inherits keyword is used with
the derived class.
By: Hitesh Santani
Example:Public Class Person
‘Members of Person classEnd ClassPublic Class Employee Inherits Person
‘Members of Employee classEnd Class
Abstraction
By: Hitesh Santani
It is a mechanism of representing essential features without including background details.
Data Abstraction increases the power of programming language by creating user defined data types.
When the classes use the concept of data abstraction, they are also known as Abstract Data Types (ADT).
Abstract Class
By: Hitesh Santani
MustInherit keyword is used to declare a class that cannot be instantiated and can be used only as a base class.
It is also called an Abstract Base Class (ABC).
Interface
By: Hitesh Santani
• Example:Public Interface person
Sub SetName(ByVal PersonName As String)Function GetName() As String
End InterfacePublic Class employee Implements person
Dim Name As StringSub SetName(ByVal PersonName As String) Implements person.SetName
Name = PersonNameEnd SubFunction GetName() As String Implements person.GetName
Return NameEnd Function
End Class
Polymorphism
By: Hitesh Santani
Poly means many and morphism means forms i.e. one name many forms.
The ability of functions and operators to act in different ways on different data types is called polymorphism.
To use one function name for many different purposes is known as function overloading.
Overloads keyword is used.
By: Hitesh Santani
• Example:Overloads Function Add(ByVal a1 As Integer,
ByVal a2 As Integer) As IntegerReturn a1+a2
End FunctionOverloads Function Add(ByVal a1 As Integer,
ByVal a2 As Integer, ByVal a3 As Integer) As IntegerReturn a1+a2+a3
End Function
Method Overriding
By: Hitesh Santani
The process in which a subclass provide a specific implementation of a method, that is already provided by one of its super classes is called Method Overriding.
The implementation in the subclass overrides (replaces) the implementation in the superclass.
By: Hitesh Santani
• Following keywords are for method overriding:– Overridable: Allows a property or method in a
class to be overridden.– Overrides: Overrides an Overridable property or
method.– NotOverridable: Prevents a property or method
from being overridden. Public methods are NotOverridable by default.
– MustOverride: Requires that a derived class override the property or method. MustOverride methods must be declared in MustInherit classes.
Event Driven Programming
By: Hitesh Santani
Event Driven Programming
By: Hitesh Santani
• Event: An event is a user action which he/she has performed for a purpose. Examples are clicking or double clicking a button, typing a character, hovering mouse pointer etc.
• Event Source: An event source is an element on the screen on which the user performs the action which triggers the event.
• Event Handler: An event handler is a set of statements which has been written to handle a specific event.
• Event Dispatcher: This is the module which handles all the triggered events and calls the appropriate event handler function.
Any Questions in this unit?
By: Hitesh Santani