ASP.NET Web Forms, a Detriment to Web Developers

I've been an ASP.NET developer for a long time, starting with classic ASP about 15 years ago, eventually moving to ASP.NET Web Forms. Nowadays I would never consider starting a new Web Forms project.

New developers, beware. Especially ones asking "Should I learn Web Forms or MVC?" (old developers, read, reminisce, weigh-in)

At first, ASP.NET Web Forms seemed great, and for the time it was. But that time has passed, and even though the ASP.NET team is still supporting Web Forms, they should be actively discouraging new developers from learning it (granted it looks like they are eventually going to pinch off that loaf of a framework, or at least make it less-recognizable). Within the past few years I started redeveloping my sites in ASP.NET MVC or Node.js. Moving to these frameworks made me wonder, was Web Forms detrimental to my ability to code web sites?

tl;dr; if you are just beginning in ASP.NET, start with ASP.NET MVC -- you'll have a better understanding of how to develop websites and can more easily switch between different development languages. Conversly, ASP.NET Web Forms teaches you how to be good at.... Web Forms. It will teach you a lot of useless tags that only work in Web Forms and make you dependent on "nice" functionalities that shield you from knowing things you actually need to know.

Here are some of the bad aspects of Web Forms and why it keeps you from being a better developer:

1. Server Controls

I can't really figure out why the hell server controls were even made. Instead of using <input type="text">, you'd use <asp:TextBox id="blah" runat="server">. Why? Why didn't ASP.NET just let us use regular HTML controls with the ability to manipulate them from the code behind?

Why it is bad: Coders don't even need to know what HTML is being rendered to the browser. They now understand <asp:Label>, <asp:HyperLink> and <asp:DropDownList>, but not the <span>, <a>, and <select> that get rendered. Not to mention all of the deceptive attributes like BorderColor that train you in poor practices like inline styling, all while separating you from the CSS. Really. Take a look at all the the Label class and then the span tag. It's like a choice between reading Moby Dick or an Archie Comic.

I see questions from Web Forms guys moving to MVC: "Where are my server controls? How do I use <asp:Grid>?"... What they should be saying is "Thank goodness, the server controls are gone." But unfortunately, they find it hard to function without the server control hand-holding. These things are the PCP of the web world. All fun and games until you try to stop using it.

And then there is the inevitable "I'm trying to access my server control in JavaScript by its ID, and it isn't working!?!?!" Yeah. Your attributes changed. Guess you didn't notice that. Now go litter your JavaScript code with <%= BunkControl.ClientID %>.

2. Event Validation

The Page.EnableEventValidation Property was created to help protect us from malicious attacks, but what it did was separate the coder from being aware of what a malicious attack is and how to appropriately protect against it. All you had to do was turn on EventValidation and go along your merry way. Ignorance is bliss.

Why it is bad: The minute you need someone to enter a < in an input, your validation would fail. Turn off event validation, and now you are vunerable. Since you've always used EventValidation, you don't know what you need to protect your self against or how.

Strangely enough, at a Microsoft conference in 2013, an unnamed big-wig actually encouraged people not to use this feature because it was flawed, and stated users are better off using other methods to protect themselves. Sometimes I think I just hallucinated the whole thing during a sweaty withdrawl period caused by not doing a line of server-controls, because I can't find where this is publicly stated. No, I'm sure of it, it really happened.

3. UpdatePanel

The UpdatePanel "enables sections of a page to be partially rendered without a postback." All you need to do is include a ScriptManager tag (see bullet 1. Useless server controls) and watch the AJAX happen, all while not coding a single thing!

Why it is bad: UpdatePanel is the fancy show hiding the Wizard of Oz. But it isn't some magical, flame-spouting all-intelligent force... it's just a front for old-man AJAX. And he's a nice guy when you get to know him. My money says most of the people using UpdatePanel just know it makes them look cool because they have no postback. AJAX, what's that? Doesn't matter, I have UpdatePanel!

4. View State

View state is the "technique used by an ASP.NET Web page to persist changes to the state of a Web Form across postbacks." 1 Similar to an UpdatePanel, View state is a feature that was created to make your life easier. Though, View state isn't like old-man AJAX, or even his crusty curtain. It's a bloated troll squatting in the background of your web application. It's the mac-daddy of all hidden form variables.

Why it is bad: Like many other Web Forms features, new developers probably don't even know it is there, hanging on the back of their webpage like a 10-pound diaper on a 5-pound baby. We all use methods to persist data, but View state was created to mimic the state you'd have in a desktop application.

That's it for this post, even though there are so many other things to discuss: javascript:__doPostBack(), the ASP.NET lifecycle (which is a bit like reading the first few chapters of the Old Testament. "And Pre-Init begat Init, who begat InitComplete, who begat PreLoad and his brother Load"), ClientScriptManager.RegisterStartupScript and other confusing features that have developers trying to manipulate client-side code from the server-side...

What Web Forms feature gave you the most heartache?