For the longest time (well, at least since April 2004 when I first installed .Text) I have wanted to add the ability to rate a web posting on my blog. It hasn’t been until recently, however, that I decided to do something about it.
It wasn’t until I was almost done with the project that I decided to do a Google search for other blog rating controls. I happened upon a Content Rater control by Scott Mitchell (of aspnet.4guysfromrolla.com. Scott’s control presents a UI reminiscent of the rating boxes found on Microsoft’s MSDN sites. Funny – that initially provided me with some of my original inspiration as well. My rating control’s UI, however, ended up completely different.
As I started in on the project I had an idea of where I wanted to end up and what functionality was desired, so I layed out some design goals:
- Take advantage of .Text’s ability to be functionally extended without needing to be recompiled. This one was pretty easy – I really didn’t have to think too hard to make this one work

- Utilize the .Text framework classes as much as possible, providing deeper integration and consistency with how the blog behaves. This was accomplished simply by referencing the various Dottext.*.dll libraries and building against them
- Minimize external dependencies. I wanted to make sure that all controls and pages were completely contained within my .dll with functionality that was homegrown or natively available in the .NET framework.
- Minimize the impact of the installation and deployment. I wanted to make the touch points as small and few as possible. This greatly increases the ease of adoption.
- Ensure proper functionality within cached parent controls. .Text will perform PartialCaching controls (i.e. @OutputCache or [PartialCaching]) to optimize server performance and minimize database hits. This isn’t without its few drawbacks. One of my primary goals was to allow my rating control to be placed on the blog’s main page along side each post (via .Text’s Day.ascx control). This control gets cached and therefore does not accept postbacks (unless the postback just happens to correspond with a cache timeout).
- Support dynamic graphics for rendering the rating (stars, dots, bars to start with). I didn’t want to have a plain-ol’ ordinary rating on my blog, but rather a nice, professional presentation. This called for writing a custom HttpHandler to take the graphics and stream them down to the client browser. If, however, this turned out to be too lengthy an operation, I could just as easily pre-gen the images and have them on-hand, ready to go.
- Be able to rate anything on the site: blog posts, comments, stories, images, etc. I didn’t want to be able to rate only blog posts. Instead, anything on the site is fair game and should be ratable – even other people’s comments! Ratings with comments would, in addition, become comments themselves.
- Be hostable anywhere on the site. As mentioned earlier, I greatly desired to be able to present the rating along side each post on the blog main page. This required that I support some properties that otherwise I wouldn’t have; properties that allow you to specify the post link (e.g. permalink) and id of the post in question.
I had a general idea of how I wanted it presented, but I could flesh that out in time and wanted to firstly ensure that I would be able to achieve the functionality desired before diving too deeply into the UI.
Ultimately, I decided to implement it as an ASP.NET WebControl rather than as a UserControl. This allowed me to distribute a single .dll and not have to worry about an additional .ascx file (or set of files). Though, perhaps, this limits me to how the control is to be rendered on the client, I feel that it wasn’t that great a sacrifice to make.
Due to how I envisioned the control being used I could not have it postback to itself directly, despite all desires to have such functionality. Therefore, I decided to have the control pop up a dialog box for the user to rate the post. I’m not a huge fan of popups my any means, but I feel that in this case they are warranted. First of all, I didn’t want to redirect the user simply to rate the page, and second, it should be a really quick operation.
In order to have a page to display (without distributing any additional files) I had to create a class that inherited from System.Web.UI.Page and drive the UI fully from within the class.
Once this functionality had been defined and the behaviors established, it was time to integrate it with my .Text blog – which will be the topic for my next post.