Skip to main content

Difference between WebForm and MVC in Asp.Net

Asp.net framework is a small part of .Net framework for building and running web applications. We can design and develop a web application or website using either Asp.Net MVC for Web Forms. In this article we will see some important difference between Asp.Net Web Forms and Asp.Net MVC.

Difference between WebForm and MVC in Asp.Net

Asp.Net Web Form Asp.Net Web MVC
Asp.Net Web Form is not an Open Source. Asp.Net Web MVC is an Open Source.
In Asp.Net you will have a server controls like TextBox, Buttons etc. In Asp.Net MVC you will have html helpers.
For client side state management Asp.Net Web Forms supports view state In Asp.Net MVC view state is not supported.
Asp.Net Web Form follows Web Forms Syntax Asp.Net MVC follow customizable syntax (by default it’a a Razor)
Asp.Net Web Form has file-based URLs that means file name exist in the URLs must have its physically file existence. Asp.Net MVC has route-based URLs means URLs are divided into controllers and actions and it is based on controller and actions, physical file is not required here.
In Asp.Net Web Form, ASPX pages are tightly coupled to Code behind(.CS). In Asp.Net MVC, design (Views) and logic(Controller) are resides separately.
In Asp.Net, for consistent look and feels we can use Master Pages. In Asp.Net, for consistent look and feels we can use Layout views.
In Asp.Net, for code re-usability we can use User controls. In Asp.Net, for code re-usability we can use Partial Views.
Asp.Net Web Form follow a traditional event driven development model. Asp.Net MVC follow MVC (Model, View, Controller) pattern based development model.
Asp.Net Web Form has built-in data controls and best for rapid development with powerful data access like repeater, grid etc. Asp.Net MVC provides full control over html markup and support many features that allow fast and agile development. Asp.Net MVC is is best for developing interactive web application with latest web standards.

I hope it will help you to identified the basic difference between Asp.Net Web Forms and Asp.Net MVC.

Introduction to Class in OOPS with C#.net

Understanding class

A class is like a blueprint. It allows us to create our own custom data types by grouping methods, events and variables of different types like int, string or any other custom types. Class defines the data and behavior of a type.

A class can be defined with a keyword “class” followed by the class name and body of the class with a pair of curly braces.
Let’s have a look at the general form of a class body.

below is the general form of a class body.

//Public is the access specifier while Calculator is the name of the class
public class Calculator
{
//variables declaration
private int var1;
private int var2;

//methods declaration
public decimal Add(decimal val1, decimal val2)
{
return val1+val2;
}
}

Classes supports inheritance while structs can’t support it.
Access specifiers plays an important role in the class definition, which specify the rules for accessing the member as well as the class itself. Default access specifier for the class is internal while for member it is private.

Data type specifies the type of variable, and return type specifies the data type of the data the method returns.

To access the class members we need to create an object of the class if class is not static, and using object name(dot)membername or member function name

See the below code for accessing Add method of Calculator class

Calculator calc = new Calculator();
decimal finalSum = calc.Add(10,20);