This weekend I had my first decent run at developing something in ASP.NET. I've tinkered about with Visual Studio in the past, but this was my first go at actually developing something rather than just throwing controls on a form to see what they could do. Overall, it was a pretty positive experience. It's amazingly frustrating to start with a new product, you know exactly what you want to do, but don't know the best way to go about doing it. I guess it's similar to learning to speak in a different language.
I had a small list of things I wanted to achieve in order to help put things into some sort of context for myself. Data access, form creation, form positioning/layout, some simple form events, that sort of thing. What I considered the building blocks of most web applications, a foundation on which I could build other, more complicated things. The basic idea for my test project is an ASP.NET version of Merauderweb, aka, Merauderweb.aspx (inspired name huh?).
The Development Environment
For now, I'm using Visual Studio 2003 for everything. It has it's quirks, but on the whole it seems like a pretty nice IDE, and one which a large amount of MS developers actually use. In order to play about with data access I obviously needed some sort of database server - I didn't have a copy of SQL server handy, so I installed MSDE. It seems to do the job fairly well, but if you have SQL Server available then you'd be much better off installing the full thing. The management interface for MSDE is pretty cheap and nasty, and there are also some management issues around security which will throw up a few problems with some examples that you might find in certain books. These can all be worked around, but it distracts you from learning about ASP.NET, and takes you into learning about MSDE. At one point I was referring to a book which had a quick example on binding data to a datagrid - the example had a quick connection string to use which simply would not work with MSDE. It was a pretty simple task for me to use the server browser and drag a SqlConnection onto my form, then copy/paste the auto-generated connection string into the code example, but that's something which might not occur to everyone.
Another thing to note with MSDE is that it doesn't come with the Northwind sample/test database. That's not a biggy, but a lot of test tools/sample codes/book references use Northwind, because as far as they're concerned "every installation of SQL comes with the Northwind sample database". Not MSDE. There is a MSI file you can grab from Microsoft downloads which will install Northwind into your MSDE setup, which is run via the osql executeable from a command prompt.
Positioning and Formatting
Data access was fairly simple to sort. For a Domino developer who was used to DbLookups and DbColumns there were a few fundamental SQL things to learn, but nothing too traumatic. Next on the list, was positioning and layout. I had data coming from my SQL database, but it was all looking pretty crappy. I added the Merauderweb CSS file, and it instantly applied the default formatting to my form - nice. I played about with the CssClass property of various elements, and I have to say, it was pretty cool having them actually update on the form itself. Yes I've always done my HTML in Notepad, and yes I still love command line interfaces, but sometimes you really can't beat a visual editing tool - especially for those times when CSS can be a bit quirky. However, I was having trouble getting things to look quite right with regards to the positioning - this is about the time where google taught me a little lesson about Visual Studio...
The pageLayout property - GridLayout vs FlowLayout
By default your forms in Visual Studio are created with the page layout set to Grid Layout mode. This is a property of the form which you can change on a solution wide level, however it's not a global option anywhere in VS. Meaning you always need to change this option at least once. In a nutshell, GridLayout uses absolute CSS positioning to make sure that every element on your form stays where you put it (well, as close as you can get with CSS anyway) when you render it on your page. This would be handy for certain web applications, but for anything with some amount of varying length content it's pretty useless. This is where flow control comes in, and it takes a much more traditional top down type approach, hence it's name.
Most of the time you'll want to be in Flow Layout mode, so it's kind of stupid that it's not the default. It's a fairly simple concept, but if you want more information then the article I found in my googling goes into more detail: Ease Control Positioning Headaches.
HTML Controls vs Web Form Controls
While playing about with the toolbox, I wondered what the difference was between these two. For example, some of the "Web Form" controls appear similar to their counterpart "HTML" controls. The basic difference is that the HTML controls won't do a postback event to the server, and so can be used to perform traditional client side operations, such as javascript execution and so on. Pretty much all of the web form variants will have the code behind them executed on the server, although sometimes this is optional.
In Summary
So now I have a little web application which displays some Merauderweb styled data in a web form in a similar sort of style to the current Merauderweb. The data is pulled from a SQL database using a very simple query. A rough plan of my next steps:
- Add a few more fields to the SQL database and put a bit more data in there
- Increase the complexity of the home page query - ie, grab the most 10 recent entries VS the "SELECT * FROM...." query that's there now (yes this is basic stuff, but for someone who's not played with SQL it has a bit of value!)
- Enhance the main page to take a category paramater, and use that to (obviously) limit categories of posts. Possibly do the same things for specified months/years as well.
- Use some shared design elements to store some site navigation code in a single place (ie, the ASP.NET equivalent of SubForms)
- Implement some sort of search feature
- Implement a comments/feedback system which would obviously update my SQL database
- Add some pages to allow content to be authored via an ASP page rather than by directly editing the database using the Server Explorer!
I'll add more as I think of them, again we're still in the "build a foundation" stage here.