ASP.NET Web Forms
In my last blog, I covered NuGet: an extension of Visual Studio that helps you integrate famous libraries and packages into your application. As I mentioned in that blog, I will be using NuGet from time to time throughout this blog series, so I went ahead and got it out of the way early. Now that you all know how to use that tool (if you don’t and haven’t read my previous blog, click here), I can start with the major technologies that are dominating the ASP.NET framework, helping us to build far better web applications than ever before.
In this blog I will be presenting to you the heart and soul of ASP.NET Technology. That’s right! The ASP.NET Web Forms that started it all. I remember starting ASP.NET 1.1 back in my university days. Ah, the golden days!
In this post you will find a brief introduction on ASP.NET Web Forms along with some details on how it works. We will then move on to practical implementation using the latest ASP.NET 4.5 Web Forms. The sections are clearly labelled (I hope) so you can find exactly what you need.
So without further ado ladies and gentlemen, ASP.NET Web Forms!
ASP.NET Web Forms
ASP.NET is an ever-growing technology for Web application development using the .NET Framework. It takes the best from its predecessor, Active Server Pages (ASP), as well as the rich services and features provided by the Common Language Runtime (CLR) then adds many new features. The result is a robust, scalable, and fast Web development experience that will give you incredible flexibility so you can develop web-based applications with ease.
What is ASP.NET Web Forms?
ASP.NET Web Forms is one of the three programming models for creating ASP.NET web sites and web applications using ASP.NET Technology with the .NET Framework. The other two programming models are ASP.NET Web Pages and ASP.NET MVC (Model-View-Controller), which I will be explaining in my coming blogs.
Web Forms is the oldest ASP.NET programming model. Web Forms are pages that are requested by end users using their browsers. These pages are written using a combination of HTML, server controls, and server code. The requested page is compiled and executed on the server and the response back is in the form of elements integrated in a neat structure with information that gives your Web applications their look and feel. This is known as a user interface (UI).
Visual Studio 2012 provides an incredibly powerful Integrated Development Environment (IDE) for you to create ASP.NET Web Forms. For example, it lets you drag and drop server controls to lay out your Web Forms page. You can then easily set properties, methods, and events for controls or for the page in order to define its behavior, look and feel, and so on. Now that we know what it is, let’s examine the different components that make up this awesome web development technology.
How does it work?
The Web Forms page is composed of 2 components:
The code-behind file, sometimes known as the class file, helps define the behavior that the page will have through server-side processed code based on page lifecycle events like page_load, page_init and webform control events available to you on the web page that you added to the visual aspx file, like an ASP Button Control Click event or a ASP Dropdown Control Selected event.
When a user requests a page using his or her browser, these components are compiled on the server using IIS and the .NET framework (which includes ASP.NET assemblies) installed on that server. Then the server, along with any requested data from the database (if any) that is needed, returns the generated html output of the page as a response that is rendered by the browser along with the defined behavior it has on certain user interactions one can do on the page. An interaction on the page is when the code-behind file sends another request to be processed, carries out the defined behavior, and renders the desired html output of the page (see the figure below for a graphical representation of this process). For example: let’s say we have a web page that displays all the zip codes in the United States and I choose the option of selecting a city using a dropdown to filter those zip codes. I would set the behavior of that dropdown in such a way that it takes a trip back to the server to give it the selected city I choose, filter the zip codes on that city, and then return the filtered zip codes back to the page to display.