First off, there’s the two worlds of doing things with ASP.NET. Actually, there’s three if you count classic ASP, but who’s looking at that? The first path that I went down in trying to wrap my head around ASP.NET was the web forms method of development. The bulk of the content online is targeted at this way of building apps, and it was the methodology switched to around the time ASP became ASP.NET. The second path is the MVC path, and we will get to that in a bit.
At first, I was happy with the materials that I had come upon for learning ASP.NET. There appeared to be no shortage of books available, and plenty of results turned up in the live.com search (37.1 million to be exact). The first book that I got from our library (yes, Microsoft has it’s own library, and it’s awesome) was ASP.NET 3.5 Step By Step. The ratings on Amazon were good, so it seemed like a reasonable starting point. For kicks, I also grabbed a couple of others.
Here’s my first problem with the ASP.NET literature that I have seen thus far. For the most part, they really, really want you to understand how ASP.NET works, internally, before you can do anything. Unfortunately for the ADHD generation, we want to build things, and we can’t be bothered with details. Page upon page upon page of HTTP pipelines and other minutia.
I myself learn from examples; preferably code tied to a real application. Too often in books, when there is sample code, the author provides a dump of the code, as if they are trying to say “look how much code I can write,” when all that does is make me want to close the book. Reading source code is hard, and certainly reading someone else’s is even harder. Truth be told, that’s why I embarked on this endeavor…to put out postings which were step by step about how I built something in the hope that some other novice would appreciate that I am going through exactly what they are going through. I know I am not the best developer out there, and I am going to make a ton of stupid mistakes, but no one wants to feel stupid when they are trying to learn something new, and stupid is all I felt trying to learn the forms method of development for ASP.NET.
ASP.NET has a very cool feature called “code behind” which basically separates the code from the HTML for your pages. I thought this was cleaner than trying to interleave the C# code into the HTML. That is until I tried to access code that wasn’t part of the code behind source. I am sure that if I had kept at it long enough I would have sorted through my issues, but for whatever reason, I could not make it work where I had a function in one .CS file and call it form a code behind file. If you are trying to do this, things to look out for are the differences between “<%=” and “<%”. That “=” matters quite a bit. Another thing to be on the look out for, which they seemingly never cover in the code samples and books, is how and when to use includes and the “using” directives. Remembering that one thing, more than anything, has caused me pain and suffering that I don’t want to recount. Again, I know I am not the ace developer, but imagine if you have read this far, you aren’t either.
Further annoyances around getting started were things like trying to find useful tutorials online. Here’s a great exercise. Perform the following searches:
- Ruby on Rails tutorial (google, live)
- Python tutorials (google, live)
- ASP.net tutorials (google, live)
Did you do it? How many clicks did it take you to get to useful information for ASP.net? You would think that first link to the W3Schools Tutorial would be a good one. It took me 5 clicks to get to the first bit of writing code. Four pages of really superfluous stuff. It actually felt like the whole site was set up for SEO and ads. Not that there’s anything wrong with that, but contrast that experience with the Ruby on Rails example. One click from the first returned link, and you are writing code. Still a doubter? Python was two clicks from the first returned link. My point in all of this is it simply shouldn’t be hard to get started with a web app platform.
In all fairness, I eventually removed the word “tutorial” from my search term and landed at the asp.net site. They have many informative articles, videos, etc, upon which to feast, but it took me a while to reduce my search terms. Unfortunately, the video content at ASP.net suffers from three issues, in my humble opinion. First, it’s dated – many of the video lessons for ASP.NET are several years old, and are specific to ASP.NET 2.0, not 3.5. The ASP.NET 3.5 videos all assume you know what the heck you are doing. Second, the bulk of the intro lesson videos that you can view display visual basic code. I was a VB6 nerd, so I can appreciate that, but it bothered me that some of the videos didn’t have C# tutorials with C# on screen. I get wanting to be language independent, but all of the tutorials should be in the two major Microsoft languages. I know that sounds like a nit, but it’s important for people trying to get up to speed on your platform. Don’t alienate them, and don’t make it hard. Third, and last, is the same fatal flaw as the books; the heavy reliance on the forms and server controls for the programming model. I get it. People want to see immediate results, and “yeah” I made a grid of data from a database, but when you have specific ideas about things you want to do, and they don’t fit into this notion of using server side controls, it gets difficult to digest the information. It simply doesn’t line up with the type of apps that breadth developers are building; it feels more geared toward enterprise developers building quick apps for intranets.
Here’s a great example of my difficulties: I wanted to connect to a database. I created a simple table in SQL Express (that alone was a fun exercise to discuss another time). I plowed through a bunch of content, all of it showing how “easy” it was to data bind controls. All well and good, but what I wanted to do was execute a query and put text on the screen. Eventually I figured out how to create a Data Set. Have a gander at this first search result which shows up when searching for “asp.net data set.” Make heads or tails of that. Oh, and don’t make the mistake of not knowing the name of the data set as defined in the properties window of Visual Studio. you kind of need to know that. I didn’t of course. Further, I took quite a bit of head banging trying to understand why I needed to declare adapter as follows:
UserWordsDSTableAdapters.UserWordsTableAdapter myAdapter = new UserWordsDSTableAdapters.UserWordsTableAdapter();
YIKES! Thank goodness for auto-complete and intellisense. Unfortunately, because C# is strongly typed, and because I couldn’t remember that the Data Set was called UserWordsDS, which then gives me the UserWordsDSTableAdapters, I had a hell of a time getting the adapter object created. Nothing about using the Data Set was easy to just wrap my brain around. Perhaps one day I will appreciate that there are Get functions that I have created which have the SQL queries in them, and in order to get the data, I have to create a UserWordsDS.UserWordsDataTable object, and then set that equal to the return value of the myAdapter.GetData() function, but I doubt it. It just feels like obfuscation for the sake of obfuscation.
Finally having the ability to get data from the database had me hopeful, but this is where I ran into the problem of not understanding why I couldn’t create a new .CS file in the project, and use the very same code that I had used in a code behind file to access data and either return a string or write the Response object. It was at this point that I threw my hands up. I actually had three different books on my desk, all in a desperate attempt to figure out how to call C# from the aspx file. I gave up. And then I discovered ASP.NET MVC. We’ll leave that post for tomorrow, but let’s just say I got more done in two hours then I did in a couple of days of “learning” traditional ASP.NET. Must be my Django and Rails tendencies coming through.