Archive for category IIS and Windows Technologies

ASP.NET Controls, How I Hate Them

MSDN Error
Image by ttrentham via Flickr

I’ve always, for some reason, felt innately that PHP allowed me more control over my code than ASP.NET. My brain kept saying “but .NET is more organized! It compiles! It’s faster! It’s easier to write,” but my mind kept saying “PHP lets me do what I want how I want it… screw .NET!”

What I finally figured out was that I love C#, I even like the .NET framework, but I hate is, in fact, ASP.NET.

Every time I see an example of simple, elegant code, the most complex control on the page is a label or a panel. While the intentions behind FormView may be good, writing my own forms and hooking them up saves hundreds of lines (literally- I just refactored almost 800 lines of code into 150 by removing a formview) as well as reduces complexity and maintenance (now I no longer have to maintain view and edit and whatever other modes FormView has.) ASP.NET perhaps made sense in a day before OO principles and ORMs came into play; the controls were written for the same kind of people that use the drag-and-drop design mode. Easy to slap down haphazardly, not so easy to maintain.

We replaced every ASP.NET Ajax control we used anywhere (after I evangelized it, to my chagrin) with jQuery after about 6 months of use; while the controls did what we needed on the surface, underneath there was always some caveat, like the linked DropDowns needed web services, or the datepicker control had missing options… there was always something somewhere that I needed a bit of flexibility on that just wasn’t there, or was buggy. It seemed very odd for it to be out of beta in such a state. So, I ended up starting my own control library using jQuery, and now it’s easily extensible, easy to modify from the client, and I can control the markup.

Oh, and the markup… don’t get me started on the markup. Tables for everything. I can’t rearrange the otherwise useful Wizard control because it’s so static in its display.

So, I guess the point I’m trying to make is, that the longer I use .NET, the less and less I use the complex controls and the more I roll my own. Because it’s easier.
Kind of ironic.

Reblog this post [with Zemanta]

Tags: , , , , , , , ,

Goodbye, Movable Type; Hello, WordPress

I’ve been using Movable Type for a few months now. I’ve liked it, but it wasn’t great; it worked well, but I wasn’t blown away. After a while, it moved slow; there was no way to remove a lot of comment spam at once (which I seemed to be particularly prone to), and I had a few bugs, such as having to log in twice each session. Maybe they weren’t all MT’s fault; but I had trouble finding support.

So, when we set up our new Windows Server 2008 machine using a 64-bit edition, I hit a wall: there’s no MySQL support for ActivePerl x64. There isn’t any official support for x86 either; but there are workarounds for that (use external repositories). It also came at a time when I was deciding whether or not I wanted to switch, so it pretty much cinched it up; I decided to try out WordPress. It was a PHP/MySQL system, both of which I had already set up, so I expected (or at least hoped) that it’d be pretty simple to get running.

The first thing I had to do was back up my old MT database. I expected some long, tortourous sequence of MySQL edits or something, but all it came down to was logging in, clicking “Import/Export”, and then export. It spit out a text file, which I saved to my desktop. Next, I unzipped a WordPress download into my blog folder (and set up the requisite site in IIS). I set up a database and a user in MySQL for my blog. I then edited the wp-config-sample.php, filling in the requisite database information and renaming it to wp-config.php, visited the site in my browser, and hit ‘go’. Seconds later, I had a new, live WP blog.

From the admin panel of my blog, I went to tools, hit “import”, selected “Movable Type” from the list, browsed to my file, and uploaded. And that was it. I had totally converted to WordPress in minutes. I was absolutely astounded by the ease. It was already much faster (with the help of WP-Cache), and running well.

Next stop: new design. WP looks like it’ll be much easier to work with, so hopefully we’ll be up soon.

Tags: , ,

Back from Vacation

Just got back from spending a week in Arizona- that’s right, the middle of the desert on the border of Mexico- where it rained for three days. We couldn’t get to part of the Grand Canyon because of the snow. In Arizona. Did I leave Ohio?

I don’t want to complain too much, though; the resort we stayed at was very nice, and Audrey’s aunt was kind enough to pay for everyone’s stay. And the Thanksgiving dinner was something I won’t forget (the link will explain all).

Anyway, first thing I did when I got back and settled (besides scavenging a cheap turkey from the grocery store… 12-pounder for $10) was delete 400ish spam messages. Sorry for the garbage; the new version of MovableType supposedly clears that issue. I also upgraded my theme; still not a custom one yet, but I’ll get there once I get the time.

I also installed Rainmeter, Samurize, and Rainlendar - they are absolutely fantastic desktop-managing applications. And, if that wasn’t enough: I installed a new hard drive and I’m in the process of installing 5 virtual drives; Windows Server 2k3 and 2k8, Windows XP, the latest version of Kubuntu, and Fedora 10. That is, if I can get the last two working with Windows Virtual PC 2k7.. I’ve seen it done, but I know it’s tricky. The goal is to have plenty of development platforms with which to do my work; I’ll be able to test web apps in the virtualized servers before I push to production on CD.

Speaking of CD, we’ve got our new website up; I was inspired by a Keane song, and somehow came up with this. My brain goes through somewhat strange processes sometimes, but I’m pretty happy with the result. JQueried it up, even, much to the chagrin of my budding Ajax framework project.

Tags: , , ,

User Controls Rock: Legos and Fake Ajax Master Pages

Let me start with a simple statement: user controls are absolutely fantastic.

If you haven’t delved into the realm of the .ascx, then let me briefly explain the two big benefits that have been relevant to me recently:

  • Totally reusable code
  • Emulate master pages; only with this, you can use the Ajax control toolkit to do it

On the first point, the reusable code point, this is the biggest. It’s the entire reason behind user controls. It lets you chunk out code that you use all over, and use it in several places; it’s a fundamental of object oriented development. Let’s do an example.

Say you have a piece of code that goes to the database and retrieves data on a member. That data is then put into a styled gridview, for the administration side of a website. But, you also have an area in a members section where a user can edit their own information (more like a formview); and, on the normal web display, casual users can browse through usernames and user roles in a paged gridview.

Don’t write the same code thrice! (or even twice!) Rather, make a user control to do all the work for you, and place it in each of your pages. This is how I’d do it:

For the sake of this article, I’m assuming you’re using a list of “Member” objects. Use whatever.

-Make a public class-level property in your control called “ReadOnly”, a bool.
-Make a public class-level method in your control called “Intialize”, which takes an IList of Member objects
-If the IList has one object, add a FormView to your control, and databind it. Otherwise, go the Gridview route (doing this all from the codebehind would keep your code cleaner and keep you from having an extra control rendered, although you could do this in the .ascx if you really wanted to; just set one to visible=”false” to the one you’re not using)
-Create all of the appropriate methods for your control for delete, update, insert, etc. and set up your formview or gridview accordingly (of course, only update for our member’s area FormView!)
-If ReadOnly is true, don’t add edit, insert, or delete buttons to your formview/gridview. (Easy enough; could set visible=”false” on the fields, or just not add them at all)

And, then, back on your three main pages, register and use your control.  Set the ReadOnly property (if it’s a bool, you should even get IntelliSense for true/false), and then on Page_Load, call Intialize on the control, passing through the IList of Members that you pulled down.

The reason we’re calling the data on the page, rather than the control, is so that the control can remain “dumb” and doesn’t need to know whether it’s a member, admin, or web display control. The less logic in the control, the better; just spit out the lowest common denominator.

Ok. Now that we’ve hit the reusable control side, let’s hit the fake-an-ajax-master-page part.

As you may or may not know, even if you wrap the ContentTemplate in a MasterPage, it still reloads every page change. This is because the MasterPage gets loaded after the rest of the page, and is treated like a control. So, if you change pages.. it loads the page, and then says afterwards, ‘oh, yeah, that was Ajax. Oh well.’

The cool thing you can do, is make one default page, and inside of that have user controls in place of your pages, something like this:

-Make your default.aspx page
-Create user controls; however, rather than logic in Page_Load of the control, put it all in a public class-level method you call Initialize.You’ll see why soon.
-Put all of your controls into your default.aspx page, with visible=”false”.
-On the onclick of your navigation buttons, run the Initialize on the control, and set it’s visible property to true, and all the others to false.. I might alternately suggest using Command and a single method rather than Onclick and seperate methods for each button, so you can pass through a CommandName, which you can then use in a switch statement and know what button you hit.

Ok. Now that we have our fancy Ajaxy page, you may be wondering: why not just visiblity? Why this Initialize thing?

This is because ASP.NET will fully render the controls, visible or not. Which means that if you have 10 pages, it will load those 10 pages and display one; which is a big performance hit on the server, especially if you’re loading database data into each of those 10. Having to explicitly call Initialize avoids this. It also allows you to pass through a common parameter to each of the controls (say, a title string that displays at the top of each control) .

Controls can certainly do much more than this; but these are the biggies for me. Have any .ascx uses of your own?

Tags: , , , , ,

Perl and Movable Type

I finally made the switch for my blog to our own server, after Don got our new server up and running. We hammered through some DNS fun and then some PHP Horror, and then, after everything was set up, it was Perl time.

What went through my head was a little chant: ‘not a PHP install all over again.. not a PHP install all over again.. not a PHP install all over again.. ‘

And, it wasn’t quite that bad. Close, but not quite. The difference was that in the Perl install, most of my guesses were correct. Because, as always, installing any non-Microsoft language on a 2k3 box with IIS is never going to be fun. I unzipped the MovableType (version 4.12) file into my web directory, and set off to configure everything. (I already had IIS and MySQL installed at this point).

That said, the first thing I did was install ActivePerl from ActiveState, version 5.10.0.1003. At the time of writing, this was the latest and greatest. I did the install (something that, if following this as instructions, I urge not to do, at least of that version… follow further down), and everything worked… except that there was no MySQL module to be found. Bummer.

So, after hours of troubleshooting that I won’t bore you with, I finally googled around and found out that the 5.8 version (5.8.8.822, to be exact) still had the MySQL module. I uninstalled the old version and installed this older version, set up the extensions (IIS manager -> web site -> right-click, properties -> home directory -> configuration, add .cgi with the extension set to the perl.exe file where you installed perl, with the headers locked down to GET, HEAD, and POST). Basically, I followed this: MT Windows Installation. However, after all that was said and done, I still had the problem of it not working.

The first problem I had was that when I went to check the install by going to mt-check.cgi, it errored out halfway down the page. So, I opened up the ActivePerl Manager and set DBI and DBD-MySQL to reinstall. I also took the -original off of the “mt-config.cgi-original” file name.

The next thing to do is to open up that config file, and comment out
all of the data sources you’re not using.  Mine looked something like:

##          Movable Type configuration file                   ##
##                                                            ##
## This file defines system-wide settings for Movable Type    ##
## In total, there are over a hundred options, but only those ##
## critical for everyone are listed below.                    ##
##                                                            ##
## Information on all others can be found at:                 ##
## config

################################################################
##################### REQUIRED SETTINGS ########################
################################################################

# The CGIPath is the URL to your Movable Type directory
CGIPath    http://www.crimsondeviations.com/blog/

# The StaticWebPath is the URL to your mt-static directory
# Note: Check the installation documentation to find out
# whether this is required for your environment.  If it is not,
# simply remove it or comment out the line by prepending a “#”.
StaticWebPath    http://www.crimsondeviations.com/blog/mt-static

#================ DATABASE SETTINGS ==================
#   REMOVE all sections below that refer to databases
#   other than the one you will be using.

##### MYSQL #####
ObjectDriver DBI::mysql
Database movabletype
DBUser ********
DBPassword *************
DBHost localhost

##### POSTGRESQL #####
#ObjectDriver DBI::postgres
#Database DATABASE_NAME
#DBUser DATABASE_USERNAME
#DBPassword DATABASE_PASSWORD
#DBHost localhost

##### SQLITE #####
#ObjectDriver DBI::sqlite
#Database /path/to/sqlite/database/file

Then again, the mt-wizard page continued to error with “CGI Error. The specified CGI application misbehaved by not returning a complete set of HTTP headers”.  After more Googling around, I found out that you have to replace a line in every page in the main directory (luckily, not many: I opened them all in Notepad++ and did a “replace all in opened files”). You have to change:
use lib $ENV{MT_HOME} ? “$ENV{MT_HOME}/lib” : ‘lib’;
to
use lib $ENV{MT_HOME} ? “$ENV{MT_HOME}/lib” : ‘Y:\www\blog\cgi-bin\mt4\lib’;
(replacing, of course, with whatever your path is).

Which then fixed my errors of it not finding the right data source, having wrong headers, and it magically worked, and I was on my way to blogdom!

Tags: , , ,