ASP.NET Web Forms was first released in 2002 as a successor to Classic ASP. It was a revolutionary technology that made the development of web pages “Event Driven in Code-Behind”. This was a great simplification in comparison to other technologies of that time and even today. This technology is still in use and its current stable version is 4.5.
With ASP.NET Core 1.0 in the picture, what does the future of Web Forms look like? Is the technology dead?
In ASP.NET Web Forms, as the name suggests, each web page is called a “Web Form”. Each Web Form has a page life cycle, which is a series of events from page initialization to page disposal. Each UI element on a Web Form is called a “Control”. The Visual Studio IDE supports full drag and drop functionality for designing Web Forms and so it’s just a matter of picking and dropping controls from the toolbox on the Web Form to wire-frame a basic web page layout.
For example, you can print a “Hello World!” message on a Web Form with the click of a button by simply typing the following into the code-behind file and then hooking this function with the “Click” event of the button in its event properties:
protected void Button1_Click(object sender, EventArgs e)
Looks really easy, right?
While this whole concept looks easy to implement, it has the following disadvantages:
- To make this code-behind event driven model work, Microsoft has used a concept called a “ViewState”. Each control has a ViewState which is basically a hidden control on the Web Form that remembers the control’s state and accordingly executes the control events on the server side. This is a major hit on performance in some cases.
- This whole concept is server-driven which doesn’t align very well with today’s paradigm, where developers want to perform much of their stuff on the client side (using Angular, for example).
- Since Web Forms have pre-defined controls to use, debugging is sometimes a pain
So does this all mean if Web Forms are dead? Certainly not in the near future! But the future is changing for sure.
Should you be choosing MVC or Web Forms may be a tricky question to some. Below are some pointers that may help you decide which one is better for you:
Choose Web Forms if:
- The developers working on your project have primary experience in WinForms. The coding model is similar, thus eliminating much of the learning curve.
- The desired development methodology is Rapid Application Development (RAD)
- The application is relatively small
- The application is internal and doesn’t demand search engine friendly URL’s. Microsoft has introduced custom routing for the latest version of Web Forms, but it isn’t as easy to use as in MVC.
Choose MVC if:
- You need full control of the rendered HTML
- The development needs to be test driven. Unit tests have been an integral part of MVC since the beginning.
- You need RESTful, search engine friendly URLs
If we look at the future, it looks that Microsoft is now focusing more on MVC web stack. ASP.NET Core 1.0 doesn’t yet support Web Forms but it does support MVC and Web API right from the first version. Since not all companies and firms are ready to invest in ASP.NET Core and incur the additional training and deployment costs that would be involved with a migration, Web Forms won’t be going anywhere fast, and that isn’t such a bad thing.
What’s your take? If you are still into Web Forms, are you planning to migrate to MVC? Share your opinion in the comments, or tweet us @goStormpath!