Why I don’t like ASP.NET anymore

When I first started using ASP.NET (back in the .NET 1.0 days), I was in awe of the sheer capabilities it offered. For a humble ASP/VB developer, this was a welcome change. The Page object model seemed to be a work of art. “Code-behind” seemed to be one of the coolest things.  

Eight years down the line, my perspective has slowly started to change. All of a sudden, I have started to question the very design of ASP.NET (at least the object model and the Page Lifecycle). I have started to feel that the design is simply over-complicated. Let me give you examples of where I feel this pinch: 

1)       Code-Behind is always a mess

For ASP developers, developing screens using C# (or VB.NET) was a boon. Spaghetti code wasn’t there any more. All the power came in the form of code-behind. I liked code-behind to start with. But as and when we started to develop complex web applications (with rich UI), the code in code-behind files simply got worse by the day.

Web Client Software factory and the MVP pattern came in to reduce this mess to some extent. But I suppose, they arrived a bit too late. By that time, you already had applications with thousands of lines of code in each code behind file. WCSF and MVP only do so much. To date, I have never seen code behind classes which are not a mess. No matter how hard you try, you cannot keep code tidy. I know it is just not me, as I see hundreds of applications in the community which have the same plight.

Have a look at this piece of code, which I simply couldn’t do anything about. I have an editable grid with two editable columns – one a dropdown and the other is a text field (date). In this event, I am basically:

  1.      Binding a list to the drop down
  2.        Adding a delete command to each row, which is enabled conditionall
  3.        Disabling the fields if the record is not a new one.

protected void gvReports_RowDataBound(object sender, GridViewRowEventArgs e)
 if (e.Row.RowType == DataControlRowType.DataRow)
            DropDownList reportTypeList = (DropDownList)e.Row.Cells[0].Controls[1];
            reportTypeList.DataSource = _reportTypes;

            Models.Report report = (Models.Report)e.Row.DataItem;

            Button deleteCommand = (Button)e.Row.Cells[2].Controls[0];

            if (report.CanDelete)
                deleteCommand.OnClientClick = string.Format(
                “if(!confirm(‘Are you sure you want to untag this report?’))return;”);
                deleteCommand.Enabled = false;

            TextBox reportDate = (TextBox)e.Row.Cells[1].Controls[1];
            reportDate.Text = report.ReportDate.ToShortDateString();

            if (report.ReportID > 0)
                reportDate.Enabled = false;
                reportTypeList.Enabled = false;

I don’t know about you, but I simply don’t like the above code block. Without hefty comments, you wouldn’t have a clue what is happening in this block. Help me make this better. Don’t even bother to ask how I did the validations for the fields in this grid. 

2) Spaghetti Code will not go away

One of the banes of ASP was spaghetti code – server script and client script being mixed together. ASP.NET removes most of the pain, but not all of it. I find myself bringing in server script in many places. Here is an example:

      ASP.NET randomly generates control ids at runtime when controls are placed in containers or they are in pages having a master. To access these controls on the client script (to do validations, changing style etc), you could end up doing something like this:

var divReports = document.getElementById(‘<%= reportsSection.ClientID %>’);
divReports.style.display = ‘none’;              

3)       No Client Side Object Model

No matter how powerful the server side object model, tons of code still needs to be written in JavaScript. The bigger problem is that ASP.NET controls don’t really have a client side object model which mirrors the server side object model. Therefore, you end up either writing a lot of spaghetti code as shown above or hacking the DOM which the server side controls creates. I see that many 3rd party controls (like Telerik, Infragistics etc) actually offer a client side object model. I am not sure why it was not offered by the ASP.NET server controls to start with.

 4)       Painfully complex page lifecycle

For people who have developed “Portal” like applications, they would more than agree with me that the code would be horrendously complex, especially the container page which hosts the user controls. There are so many subtleties in the order of the events between the page and the user controls; you would get lost debugging through it. ViewState and master page add to the spice. Sometimes you begin to think that the idea of System.Web.UI.Control was a bad one. 

I have provided a few examples why I have started to dislike ASP.NET. I strongly believe MVC is the right way to develop ASP.NET applications. But unfortunately, it has arrived way too late for ASP.NET developers and the damage has already been done. Moreover, application stakeholders would have concerns to develop stuff on MVC as there is not much 3rd party control support as of now. In other words, developing rich UI with MVC would just be too big a challenge to deal with. Be that as it may, code behind will stay for some more time to come, and that is unfortunate.


4 thoughts on “Why I don’t like ASP.NET anymore”

  1. I couldn’t agree more…

    what’s more, the setup of the code was the worst of all possible worlds…it abstracted away the html markup, but it didn’t do it in a really nice model that implemented your intentions
    Because it’s so open ended and extensible, you find that you basically have to do everything from scratch every time.
    The web is the culprit really because it’s such a moving target and it keeps evolving technologies as well as versions.
    but I just never believed that ASP.net, as powerful as it was, had any real elegance to it.
    To me it never felt in any way enjoyable. You couldn’t really express yourself with it
    you just had to do everything in this clunky lifecyble Page way and what it ouptut was pretty ugly and messy, not to mention huge if you sent the state with it…

  2. I’m a year late with reading this but I disagree. If the code is designed properly using the SOLID principles, the “spaghetti” code goes away. Granted, the design does make things a bit harder to trace initially until one is familiar with design patterns. Then the developer simply has to extend the basic functionality to meet the new customizations and all code is neat and tidy.

    As for page lifecycles, given the lack of postback from ASP.NET’s predecessor (Classic ASP), it is nice to have the control. I am currently working on an app that is primarily ASP but I am dovetailing ASP.NET into it. We are limited to the customizations we can do using HTML, javascript and vbscript and there is spaghetti code there in order to accommodate the customizations that they *DID* allow. But I am redesigning a code feature using ASP.NET and I will be able to provide customers what they want and my code base remains untouched.

  3. At first I felt like you with the advent of mvc, but I still feel compelled to watch those old wild wild west movies – arent they the best 🙂

  4. Well, I learned C# in the .NET 1.0 days too, but oddly I have only recently started learning ASP.NET (I used C# for Winforms) and I find it steeper than learning C++. (Perhaps I struggle with the high level of abstraction?) However, as a hobbyist and web master I can’t really see why I need it. I suspect that it is useful for very complex business apps that may be used by big business, but is it really useful for someone like me, who has a content-based web site? It feels like using a sledgehammer to crack a nut. I think the problem is, many peeps want their Web browser to run like a desktop OS. Many complain about the memory usage of web browsers, trying to implement fancy features. Is it always necessary to have complicated interfaces on the Web? Must we always use OOP? Can’t we keep things simple? I probably sound naive, so enlighten me. I have been searching for good examples of web sites that I may use that use ASP.NET in a way that justifies its complexity, but I have not found any, nobody is telling. Is it just a ‘big business’ thing? Please enlighten me!

Leave a Reply

Your email address will not be published. Required fields are marked *