0% found this document useful (0 votes)
32 views28 pages

Unit 1 1

ASP.NET is a web development platform that operates on the HTTP protocol, enabling the creation of robust web applications using various programming languages such as C# and Visual Basic.Net. The .NET Framework, introduced by Microsoft, serves as a software development platform that supports multiple application types and includes components like CLR, CTS, and BCL. The Just-In-Time (JIT) compiler within the CLR enhances performance by converting intermediate language code into machine code as needed.

Uploaded by

Patel Shubham
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)
32 views28 pages

Unit 1 1

ASP.NET is a web development platform that operates on the HTTP protocol, enabling the creation of robust web applications using various programming languages such as C# and Visual Basic.Net. The .NET Framework, introduced by Microsoft, serves as a software development platform that supports multiple application types and includes components like CLR, CTS, and BCL. The Just-In-Time (JIT) compiler within the CLR enhances performance by converting intermediate language code into machine code as needed.

Uploaded by

Patel Shubham
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/ 28

Bhagwan Mahavir College of Computer Application

Subject Code : 1020201304


Subject Name : ASP.NET
Unit – 1 ASP.NET
Topic: WHAT IS ASP.NET
2

ASP.NET is a web development platform, which provides a programming


model, a comprehensive software infrastructure and various services
required to build up robust web applications for PC, as well as mobile
devices.
ASP.NET works on top of the HTTP protocol, and uses the HTTP commands
and policies to set a browser-to-server bilateral communication and
cooperation.
ASP.NET is a part of Microsoft .Net platform. ASP.NET applications are
compiled codes, written using the extensible and reusable components or
objects present in .Net framework. These codes can use the entire
hierarchy of classes in .Net framework.
3

The ASP.NET application codes can be written in any of the following


languages:
-- C#
-- Visual Basic.Net
-- Jscript
-- J#
ASP.NET is used to produce interactive, data-driven web applications over
the internet. It consists of a large number of controls such as text boxes,
buttons, and labels for assembling, configuring, and manipulating code to
create HTML pages.
Introduction to .NET Framework
The .NET Framework is a software development platform that was introduced by
Microsoft in the late 1990 under the NGWS. On 13 February 2002, Microsoft launched
the first version of the .NET Framework, referred to as the .NET Framework 1.0.

In this section, we will understand the .NET Framework,


characteristics, components, and its versions.

What is .NET Framework


It is a virtual machine that provide a common platform to run an application that was
built using the different language such as C#, VB.NET, Visual Basic, etc. It is also used
to create a form based, console-based, mobile and web-based application or services
that are available in Microsoft environment. Furthermore, the .NET framework is a pure
object oriented, that similar to the Java language. But it is not a platform independent
as the Java. So, its application runs only to the windows platform.

The main objective of this framework is to develop an application that can run on
the windows platform. The current version of the .Net framework is 4.8.

Note: The .NET Framework is not only a language, but it is also a software and language
neutral platform.
Components of .NET Framework
There are following components of .NET Framework:

1. CLR (Common Language Runtime)

2. CTS (Common Type System)

3. BCL (Base Class Library)

4. CLS (Common Language Specification)

5. FCL (Framework Class Library)

6. .NET Assemblies

7. XML Web Services

8. Window Services

CLR (common language runtime)

It is an important part of a .NET framework that works like a virtual component of the
.NET Framework to executes the different languages program like c#, Visual Basic, etc.
A CLR also helps to convert a source code into the byte code, and this byte code is
known as CIL (Common Intermediate Language) or MSIL (Microsoft Intermediate
Language). After converting into a byte code, a CLR uses a JIT compiler at run time
that helps to convert a CIL or MSIL code into the machine or native code.

CTS (Common Type System)

It specifies a standard that represent what type of data and value can be defined and
managed in computer memory at runtime. A CTS ensures that programming data
defined in various languages should beinteract with each other to share information.
For example, in C# we define data type as int, while in VB.NET we define integer as a
data type.

BCL (Base Class Library)

The base class library has a rich collection of libraries features and functions that help
to implement many programming languages in the .NET Framework, such as C #, F #,
Visual C ++, and more. Furthermore, BCL divides into two parts:

1. User defined class library

o Assemblies - It is the collection of small parts of deployment an


application's part. It contains either the DLL (Dynamic Link Library) or exe
(Executable) file.

1. In LL, it uses code reusability, whereas in exe it contains only


output file/ or application.

2. DLL file can't be open, whereas exe file can be open.

3. DLL file can't be run individually, whereas in exe, it can run


individually.

4. In DLL file, there is no main method, whereas exe file has main
method.

2. Predefined class library

o Namespace - It is the collection of predefined class and method that


present in .Net. In other languages such as, C we used header files, in
java we used package similarly we used "using system" in .NET, where
using is a keyword and system is a namespace.

CLS (Common language Specification)

It is a subset of common type system (CTS) that defines a set of rules and regulations
which should be followed by every language that comes under the .net framework. In
other words, a CLS language should be cross-language integration or interoperability.
For example, in C# and VB.NET language, the C# language terminate each statement
with semicolon, whereas in VB.NET it is not end with semicolon, and when these
statements execute in .NET Framework, it provides a common platform to interact and
share information with each other.

Microsoft .NET Assemblies

A .NET assembly is the main building block of the .NET Framework. It is a small unit of
code that contains a logical compiled code in the Common Language infrastructure
(CLI), which is used for deployment, security and versioning. It defines in two parts
(process) DLL and library (exe) assemblies. When the .NET program is compiled, it
generates a metadata with Microsoft Intermediate Language, which is stored in a file
called Assembly.

FCL (Framework Class Library)

It provides the various system functionality in the .NET Framework, that includes
classes, interfaces and data types, etc. to create multiple functions and different types
of application such as desktop, web, mobile application, etc. In other words, it can be
defined as, it provides a base on which various applications, controls and components
are built in .NET Framework.

Key Components of FCL

1. Object type

2. Implementation of data structure

3. Base data types

4. Garbage collection

5. Security and database connectivity

6. Creating common platform for window and web-based application

Characteristics of .NET Framework


1. CLR (Common Language Runtime)

2. Namespace - Predefined class and function

3. Metadata and Assemblies

4. Application domains

5. It helps to configure and deploy the .net application

6. It provides form and web-based services

7. NET and ASP.NET AJAX

8. LINQ

9. Security and Portability

10. Interoperability

11. It provides multiple environments for developing an application

Versions of .NET Framework


1. On 13 February 2002, Microsoft launched first version of .Net framework 1.0.

2. The second version 2.0 of .net framework was launched on 22 January 2006.

3. Third version 3.0 of .Net framework was released on 21 November 2006.

4. A .Net framework version 3.5 was released on 19 November 2007.

5. Version 4.0 of .Net framework was released on 29 September 2008

6. Version 4.5 of .Net framework was released on 15 August 2012.

7. .Net framework 4.5.1 version was announced on 17 October 2013

8. On 5 May 2014, a 4.5.2 version of .Net framework was released.

9. .Net framework 4.6 version was announced on 12 November 2014

10. .Net framework 4.6.1 version was released on 30 October 2015

11. .Net framework 4.6.2 version was announced on March 30, 2016

12. .Net framework 4.7 version was announced on April 5, 2017

13. .Net framework 4.7.1 version was announced on October 17, 2017

14. Version 4.7.2 of .Net framework was released on 30 April 2018.

15. And currently we are using .Net framework version 4.8 that was released on 18
April 2019
What is Just-In-Time(JIT) Compiler in .NET
 Last Updated : 14 Nov, 2019

Just-In-Time compiler(JIT) is a part of Common Language Runtime (CLR) in .NET which is responsible for
managing the execution of .NET programs regardless of any .NET programming language. A language-specific
compiler converts the source code to the intermediate language. This intermediate language is then converted
into the machine code by the Just-In-Time (JIT) compiler. This machine code is specific to the computer
environment that the JIT compiler runs on.
Working of JIT Compiler: The JIT compiler is required to speed up the code execution and provide support
for multiple platforms. Its working is given as follows:

The JIT compiler converts the Microsoft Intermediate Language(MSIL) or Common Intermediate
Language(CIL) into the machine code. This is done before the MSIL or CIL can be executed. The MSIL is
converted into machine code on a requirement basis i.e. the JIT compiler compiles the MSIL or CIL as
required rather than the whole of it. The compiled MSIL or CIL is stored so that it is available for subsequent
calls if required.
Types of Just-In-Time Compiler: There are 3 types of JIT compilers which are as follows:

1. Pre-JIT Compiler: All the source code is compiled into the machine code at the same time in a single
compilation cycle using the Pre-JIT Compiler. This compilation process is performed at application
deployment time. And this compiler is always implemented in the Ngen.exe (Native Image Generator).
2. Normal JIT Compiler: The source code methods that are required at run-time are compiled into machine
code the first time they are called by the Normal JIT Compiler. After that, they are stored in the cache and
used whenever they are called again.

3. Econo JIT Compiler: The source code methods that are required at run-time are compiled into machine
code by the Econo JIT Compiler. After these methods are not required anymore, they are removed.
Advantages of JIT Compiler:
 The JIT compiler requires less memory usage as only the methods that are required at run-time are
compiled into machine code by the JIT Compiler.
 Page faults are reduced by using the JIT compiler as the methods required together are most probably in the
same memory page.
 Code optimization based on statistical analysis can be performed by the JIT compiler while the code is
running.
Disadvantages of JIT compiler:
 The JIT compiler requires more startup time while the application is executed initially.
The cache memory is heavily used by the JIT compiler to store the source code methods that are required at
run-time.

Common Language Runtime (CLR) in vb.net


 Difficulty Level : Medium
 Last Updated : 05 Jun, 2020
CLR is the basic and Virtual Machine component of the .NET Framework. It is the run-time enviornment
in the .NET Framework that runs the codes and helps in making the development process easier by providing
the various services. Basically, it is responsible for managing the execution of .NET programs regardless of
any .NET programming language. Internally, CLR implements the VES(Virtual Execution System) which is
defined in the Microsoft’s implementation of the CLI(Common Language Infrastructure).
The code that runs under the Common Language Runtime is termed as the Managed Code. In other words, you
can say that CLR provides a managed execution enviornment for the .NET programs by improving the
security, including the cross language integration and a rich set of class libraries etc. CLR is present in every
.NET framework verison. Below table illustrate the CLR version in .NET framework.
CLR Versions .NET Framework Versions

1.0 1.0

1.1 1.1

2.0 2.0

2.0 3.0

2.0 3.5

4 4

4 4.5(also 4.5.1 & 4.5.2)

4 4.6(also 4.6.1 & 4.6.2)

4 4.7(also 4.7.1 & 4.7.2)

Below diagram illustrate how CLR is associated with the operating system/hardware along with the class
libraries. Here, the runtime is actually CLR.
Role of CLR in the execution of a C# program
 Suppose you have written a C# program and save it in a file which is known as the Source Code.
 Language specific compiler compiles the source code into the MSIL(Microsoft Intermediate
Language) which is also know as the CIL(Common Intermediate Language) or IL(Intermediate
Language) along with its metadata. Metadata includes the all the types, actual implementation of each
function of the program. MSIL is machine independent code.
 Now CLR comes into existence. CLR provides the services and runtime environment to the MSIL code.
Internally CLR includes the JIT(Just-In-Time) compiler which converts the MSIL code to machine code
which further executed by CPU. CLR also uses the .NET Framework class libraries. Metadata provides
information about the programming language, environment, version, and class libraries to the CLR by
which CLR handles the MSIL code. As CLR is common so it allows an instance of a class that written in a
different language to call a method of the class which written in another language.
Main Components of CLR

As the word specify, Common means CLR provides a common runtime or execution environment as there are
more than 60 .NET programming languages.
Main components of CLR:
 Common Language Specification (CLS)
 Common Type System (CTS)
 Garbage Collection (GC)
 Just In – Time Compiler (JIT)
Common Language Specification (CLS):
It is responsible for converting the different .NET programming language syntactical rules and regulations into
CLR understandable format. Basically, it provides the Language Interoperability. Language Interoperability
means to provide the execution support to other programming languages also in .NET framework.
Language Interoperability can be achieved in two ways :
i. Managed Code: The MSIL code which is managed by the CLR is known as the Managed Code. For
managed code CLR provides three .NET facilities:

 CAS(Code Access Security)


 Exception Handling
 Automatic Memory Management.
ii. Unmanaged Code: Before .NET development the programming language like .COM Components &
Win32 API do not generate the MSIL code. So these are not managed by CLR rather managed by
Operating System.
Common Type System (CTS):
Every programming language has its own data type system, so CTS is responsible for understanding all the
data type systems of .NET programming languages and converting them into CLR understandable format
which will be a common format.
There are 2 Types of CTS that every .NET programming language have :
1. Value Types: Value Types will store the value directly into the memory location. These types work with
stack mechanism only. CLR allows memory for these at Compile Time.
2. Reference Types: Reference Types will contain a memory address of value because the reference types
won’t store the variable value directly in memory. These types work with Heap mechanism. CLR allots
memory for these at Runtime.
Garbage Collector:
It is used to provide the Automatic Memory Management feature. If there was no garbage collector,
programmers would have to write the memory management codes which will be a kind of overhead on
programmers.
JIT(Just In Time Compiler):
It is responsible for converting the CIL(Common Intermediate Language) into machine code or native code
using the Common Language Runtime environment.
Benefits of CLR:
 It improves the performance by providing a rich interact between programs at run time.
 Enhance portability by removing the need of recompiling a program on any operating system that supports
it.
 Security also increases as it analyzes the MSIL instructions whether they are safe or unsafe. Also, the use
of delegates in place of function pointers enhance the type safety and security.
 Support automatic memory management with the help of Garbage Collector.
 Provides cross-language integration because CTS inside CLR provides a common standard that activates
the different languages to extend and share each other’s libraries.
 Provides support to use the components that developed in other .NET programming languages.
 Provide language, platform, and architecture independence.
 It allows easy creation of scalable and multithreaded applications, as the developer has no need to think
about the memory management and security issues.

Note: Much of the disadvantages of the JIT compiler can be handled using the Ahead-of-time (AOT)
compilation. This involves compiling the MSIL into machine code so that runtime compilation is not required
and the machine code file can be executed natively.
1.4 What is Code Behind?
Code Behind refers to code for ASP.NET page which is contained within a
separate class file. It is composed in a different class record that can have
the extension of .aspx.cs or .aspx.vb relying upon the language used. It
allows a clean separation of HTML from the presentation logic. In
the code-behind file, you create a class (which can be any class derived
from the Page class) that serves as the base class for the web page you
create in the .aspx file. This relationship between your class and the web
page is established by a Page directive at the top of the .aspx file:
< %@ Page inherits="NewPage" % >

The inherits attribute identifies the class created in the code-behind file
from which this .aspx file will derive. One major point of Code Behind is
that the code for all the Web pages is compiled into a DLL file that allows
the web pages to be hosted free from any Inline Server Code.

What is Inline Code?


Inline Code is embedded directly within the ASP.NET page that has an
extension of .aspx . It permits the code to be composed along with the
HTML source code using a < Script > tag. When the page is deployed, the
source code is deployed along with the Web Forms page , because it is
physically in the .aspx file. However, you do not see the code, only the
results are rendered when the page runs.
There are some basic programming concepts in OOP:

 Abstraction - The abstraction is simplifying complex reality by modeling classes appropriate to the problem.
 Polymorphism - The polymorphism is the process of using an operator or function in different ways for
different data input.
 Encapsulation - The encapsulation hides the implementation details of a class from other objects.
 Inheritance - The inheritance is a way to form new classes using classes that have already been defined.

OOPS Concepts, Features &


Fundamentals in C# with example
OOPS contains list of elements that are very helpful to make object oriented programming stronger. Here is the list of
OOPS concepts that we can implement in all major programming languages like c#.

1. Class
A class is a collection of objects and represents description of objects that share same attributes and actions.

A class describes in abstract all of the characteristics and behaviour of a type of object.

Once instantiated, an object is generated that has all of the methods, properties and other behaviour defined within
the class.

A class should not be confused with an object. The class is the abstract concept for an object that is created at design -
time by the programmer. The objects based upon the class are the concrete instances of the class that occur at run-
time. For example, the Car class will define that all cars have a make, model and colour.

Here is the syntax and declaration example of Class:

using System;

namespace oops
{

//class definition
public class SimpleHelloWorld
{
//Entry point of the program
static void Main(string[] args)
{
//print Hello world"
Console.WriteLine("Hello World!");
}
}

}
2. Objects
Objects are basic building blocks of a C# OOP program. An object is a combination of data and methods. The data
and the methods are called members of an object. In an OOP program, we create objects. These objects communicate
together through methods. Each object can receive messages, send messages and process data.

There are two steps in creating an object. First, we define a class. A class is a template for an object. It is a blueprint
which describes the state and behavior that the objects of the class all share. A class can be used to create many
objects. Objects created at runtime from a class are called instances of that particular class.

For example, A “Bike” usually has common elements such as bike color, engine, mileage etc. In OOP terminology
these would be called as a Class Properties or Attributes of a Bike object. Here is the example of Object:

3. Method
Methods are functions defined inside the body of a class. They are used to perform operations with the attributes of
our objects. Methods bring modularity to our programs.

Methods are essential in the encapsulation concept of the OOP paradigm. For example, we might have a Connect()
method in our AccessDatabase class. We need not to be informed how exactly the method Connect() connects to the
database. We only have to know that it is used to connect to a database. This is essential in dividing responsibilities
in programming, especially in large applications.

using System;

namespace oops
{
class customer
{
// Member Variables
public int CustID;
public string Name;
public string Address;

//constuctor for initializing fields


customer()
{
CustID=1101;
Name="Tom";
Address="USA";
}

//method for displaying customer records (functionality)


public void displayData()
{
Console.WriteLine("Customer="+CustID);
Console.WriteLine("Name="+Name);
Console.WriteLine("Address="+Address);
}
// Code for entry point
}
}

Now, to access cutomer class, we need create the object of the cutomer class and then access it Methods and objects.

class customer
{
// class members code

//Entry point
static void Main(string[] args)
{
// object instantiation
customer obj = new customer();

//Method calling
obj.displayData();

//fields calling
Console.WriteLine(obj.CustID);
Console.WriteLine(obj.Name);
Console.WriteLine(obj.Address);
}

4. Encapsulation
Encapsulation is implemented
class. the process ofby
keeping
using access
or enclosing
specifiers.
one orAnmore
access
items
specifier
withindefines
a singlethe
physical
scope and
or logical
visibility
package.
of a In

Encapsulation is the mechanism that binds together the code and the data it manipulates,
and keeps both safe from outside interference and misuse. In OOP, code and data may be
combined in such a way that a self-contained box is created. When code and data are
linked together in this way, an object is created and encapsulation exists.

Within an object, code, data or both may be private or public to that object. Private code is
known to and accessible only by another part of the object, that is private code or data may
not be accessible by a piece of the program that exists outside the object. When the code
and data is public, other portions of your program may access it even though it is defined
within an object.

private string GetEngineMakeFormula()


{

private string formula = "a*b";

return formula;

Example – [Encapsulation]
public class Bike
{

public int mileage = 65;

public string color = "Black";


private string formula = "a*b";

//Its public – so accessible outside class


public int GetMileage()

return mileage;

//Its public – so accessible outside class

public string GetColor()


{

return color;

//Its private – so not accessible outside class

private string GetEngineMakeFormula()


{
return formula;

}
}

public class Program


{

public static void Main(string[] args)

{
Bike objBike = new Bike();

Console.WriteLine("Bike mileage is : " + objBike.GetMileage()); //accessible outside "Bike"

Console.WriteLine("Bike color is : " + objBike.GetColor()); //accessible outside "Bike"


//we can't call this method as it is inaccessible outside "Bike"

//objBike.GetEngineMakeFormula(); //commented because we can't access it


Console.Read();
}
}

Output: https://dotnetfiddle.net/scAgvm

Bike mileage is : 65
Bike color is : Black

5. Abstraction
C# allows both classes and functions to be declared abstract using the abstract keyword.
You can't create an instance of an abstract class. An abstract member has a signature but
no function body and they must be overridden in any non-abstract derived class. Abstract
classes exist primarily for inheritance. Member functions, properties and indexers can be
abstract. A class with one or more abstract members must be abstract as well. Static
members can't be abstract.

In this example, we are declaring an abstract class Employess with a method displayData()
that does not have an implementation. Then we are implementing the displayData() body
in the derived class. One point to be noted here is that we have to prefixe the abstract
method with the override keyword in the derived class.
using System;
namespace oops
{
//abstract class
public abstract class Employess
{
//abstract method with no implementation
public abstract void displayData();
}

//derived class
public class test : Employess
{
//abstract class method implementation
public override void displayData()
{
Console.WriteLine("Abstract class method");
}
}
class abstractClass
{
static void Main(string[] args)
{
// class instance
new test().displayData();
}
}
}

6. Inheritance
The inheritance is a way to form new classes using classes that have already been defined. The newly formed classes
are called derived classes, the classes that we derive from are called base classes. Important benefits of inheritance
are code reuse and reduction of complexity of a program. The derived classes (descendants) override or extend the
functionality of the base classes (ancestors).

using System;
namespace oops
{
//Base Class
public class Father
{
public void FatherMethod()
{
Console.WriteLine("this property belong to Father");
}
}

//Derived class
public class Child : Father
{
public void ChildMethod()
{
Console.WriteLine("this property belong to Child");
}
}
class Inheritance
{
//Entry point
static void Main(string[] args)
{

Father fObj = new Father();


fObj.FatherMethod();

//Here Child object can access both class methods


Child cObj = new Child();
cObj.FatherMethod();
cObj.ChildMethod();
}
}

7. Polymorphism
Polymorphism is a Greek word, meaning "one name many forms". In other words, one object has many forms or has one
name with multiple functionalities. "Poly" means many and "morph" means forms. Polymorphism provides the ability to a
class to have multiple implementations with the same name. It is one of the core principles of Object Oriented
Programming after encapsulation and inheritance. In this article, you'll learn what polymorphism is, how it works, and how
to implement polymorphism in C#.

Types of Polymorphism
There are two types of polymorphism in C#:

 Static / Compile Time Polymorphism.


 Dynamic / Runtime Polymorphism.
Static or Compile Time Polymorphism
It is also known as Early Binding. Method overloading is an example of Static Polymorphism. In overloading, the method /
function has a same name but different signatures. It is also known as Compile Time Polymorphism because the decision
of which method is to be called is made at compile time. Overloading is the concept in which method names are the
same with a different set of parameters.

Here C# compiler checks the number of parameters passed and the type of parameter and make the decision of which
method to call and it throw an error if no matching method is found.

In the following example, a class has two methods with the same name "Add" but with different input parameters (the first
method has three parameters and the second method has two parameters).

1. public class TestData


2. {
3. public int Add(int a, int b, int c)
4. {
5. return a + b + c;
6. }
7. public int Add(int a, int b)
8. {
9. return a + b;
10. }
11. }
12. class Program
13. {
14. static void Main(string[] args)
15. {
16. TestData dataClass = new TestData();
17. int add2 = dataClass.Add(45, 34, 67);
18. int add1 = dataClass.Add(23, 34);
19. }
20. }

Dynamic / Runtime Polymorphism


Dynamic / runtime polymorphism is also known as late binding. Here, the method name and the method signature
(number of parameters and parameter type must be the same and may have a different implementation). Method
overriding is an example of dynamic polymorphism.

Method overriding can be done using inheritance. With method overriding it is possible for the base class and derived
class to have the same method name and same something. The compiler would not be aware of the method available for
overriding the functionality, so the compiler does not throw an error at compile time. The compiler will decide which
method to call at runtime and if no method is found then it throws an error.

1. public class Drawing


2. {
3. public virtual double Area()
4. {
5. return 0;
6. }
7. }
8.
9. public class Circle : Drawing
10. {
11. public double Radius { get; set; }
12. public Circle()
13. {
14. Radius = 5;
15. }
16. public override double Area()
17. {
18. return (3.14) * Math.Pow(Radius, 2);
19. }
20. }
21.
22. public class Square : Drawing
23. {
24. public double Length { get; set; }
25. public Square()
26. {
27. Length = 6;
28. }
29. public override double Area()
30. {
31. return Math.Pow(Length, 2);
32. }
33. }
34.
35. public class Rectangle : Drawing
36. {
37. public double Height { get; set; }
38. public double Width { get; set; }
39. public Rectangle()
40. {
41. Height = 5.3;
42. Width = 3.4;
43. }
44. public override double Area()
45. {
46. return Height * Width;
47. }
48. }
49.
50. class Program
51. {
52. static void Main(string[] args)
53. {
54.
55. Drawing circle = new Circle();
56. Console.WriteLine("Area :" + circle.Area());
57.
58. Drawing square = new Square();
59. Console.WriteLine("Area :" + square.Area());
60.
61. Drawing rectangle = new Rectangle();
62. Console.WriteLine("Area :" + rectangle.Area());
63. }
64. }

The compiler requires an Area() method and it compiles successfully but the right version of the Area() method is not
being determined at compile time but determined at runtime. Finally the overriding methods must have the same name
and signature (number of parameters and type), as the virtual or abstract method defined in the base class method and
that it is overriding in the derived class.
1.7 event-driven programming

After you design the look of your ASP.NET page using ASP.NET controls,
you need to add the application logic. ASP.NET introduces the concept
of an event-driven programming. It enables you to write code that
executes in response to events raised by particular user actions. Events
can be related to the page or the controls on the page. For example,
you can write code to make your application do something when the
page loads or a button is clicked.

Handling Page Events


whenever you request an ASP.NET page, a particular set of events is
raised in a particular sequence. This sequence of events is called the
page execution lifecycle.

Common events and their event handler names

Event name Event handler name Applies to

BubbleEvent OnBubbleEvent All controls

CheckedChanged OnCheckedChanged CheckBox

Click OnClick Button, LinkButton, ImageButton

DataBinding OnDataBinding All controls

Init OnInit All controls

ItemCreated OnItemCreated Repeater

ItemDataBound OnItemDataBound Repeater

Load OnLoad All controls

PreRender OnPreRender All controls

SelectedIndexChanged OnSelectedIndexChanged DataGrid, DataList, CheckBoxList, DropDownList, ListBox,


Common events and their event handler names

Event name Event handler name Applies to

RadioButtonList

TextChanged OnTextChanged TextBox

Unload OnUnload All controls

You might also like