[Coding] A Short Rant on ASP.NET
Posted by Khatharsis on November 24, 2013
Sometimes, I feel like Microsoft tends to make things more complicated than necessary. I’m sure there were good intentions with ASP.NET’s architecture, but after spending some time reading about the page life cycle, various server controls, and a bunch of other stuff, I want to toss it all in the air. This also goes back to my initial issue of finding how to properly integrate JavaScript into an ASP.NET app.
If anything, ASP.NET does a fantastic job of separating client-side from server-side, so much so that it’s difficult to set a good practice of integrating JavaScript onto an ASP.NET page. I feel quite dirty trying to integrate AJAX functionality because I have to balance server controls with raw HTML. Server controls don’t talk nicely to JavaScript except through an attribute (e.g., OnClientClick).
Then, there is the ViewState gibberish that gets generated, creating more text that has to be transmitted to the browser. Couple that with the JavaScript that ASP.NET natively generates for validation and script management and the resulting code is much larger than absolutely necessary.
Another point of contention is everything is wrapped up in form tags. Setting up a raw HTML button will fire the submit routine and the only way to stop this is to set the onclick attribute to return false. This can cause problems if, for a very simple example, you just want to display the current time when a user clicks on a button via an AJAX call. It seems a little strange to “return false” at the end of that click handler just to stop postback from occurring.
I recently read an article on why ASP.NET’s UpdatePanels are dangerous which helps drive home the unnecessary text that is sent back and forth between the user and the server. Again, just to do something as simple as printing out the current date can result in multiple lines.
All that said, I should balance out the bad parts of ASP.NET with some of the good parts that I’ve found. Or, not necessarily good parts, but convenient parts.
Server controls are handy things. For example, letting ASP.NET handle the generation of tables of data pulled from a database is time-saving. When I don’t have to worry about client-side convenience, server controls are easy to work with in terms of updating, pulling, and setting values.