There's so much hype about ASP.NET MVC these days, but the truth is that ASP.NET webforms is not going anywhere for some time. Is there any way for current developers to optimize ASP.NET webforms to perform as fast as ASP.NET MVC?
I have noticed a significant difference in speed between ASP.NET MVC and ASP.NET webforms. MVC is a lot snappier and loads pages faster than webforms. Can I achieve the same with ASP.NET webforms by optimizing it? If yes, what would you recommend?
In your page directive do the following:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="TestApp._Default" EnableViewState="false" %>
Mainly turning off ViewState
will make up a majority of the difference in page performance. Also limitting the use of WebForm controls will also make your HTML served up a lot less verbose as they tend to produce very verbose HTML.
On the other hand doing so is almost like cutting away some of the large advantages to WebForms. The controls and the abstracting of state by using ViewState
is some of the main reason's why WebForms is so popular today.
I do a lot of WebForms development still and do MVC as well. Having knowledge of both and their strengths will help you create a performant app in either framework. When I create any new WebForms app, the first thing I do is to wrap pages in a Panel
make sure to disable ViewState
for the entire panel. As I develop, and I find a use for the ViewState
(eg. to save me time or simplify things) I turn it on case by case so I understand why I am using it and make a consious decision to add the overhead to my page.
WebForms can be just as fast as MVC if you approach your web app with performance in mind but it's very easy to make it much slower if you want to just ignore performance and just get the app done.
The technology does not matter, how you implement your application does. One can argue ViewState would make a difference but that is also an implementation detail. ViewState is not required and you can also leave it on the server. At the end of the day both of these technologies deliver HTML over HTTP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With