BlogEngine.Net 1.XX where have you gone?

How to Create a Threaded Comment System with ASP.NET

4. February 2009 03:49 by Scott in   //  Tags: , , , , ,   //   Comments (1)

A few days ago I was designing a threaded comment system for Drinkingfor.com which allows users to reply back to other users directly instead of a flat comment system like you see at most other places.  I made my argument for threaded comments over here and why they should be used.  I didn't know where to start or how to write the code.  I had a pretty good idea on database design which was decently simple.  Each comment shall have an owner comment.  The treeview is the best example of what the data in the database should look like.  As for how to display this out to code is another problem.  I ended up searching on the internet and found a man who created hierarchy class which is exactly what I needed.  The Hierarchy class selects the information from the database and organizes it into a cached treeview.  I ended up talking to him and he had explained to me that he was refactoring the class which will allow it to run faster.  As for how I implemented the code to write out HTML, I ran through the hierarchy class recursively and then created html for each node found.  The class was quite impressive and I included some sample code below.  I didn't want something like this to be wasted and hope everyone can put it to good use.


Photo by jurvetson

I also wanted to give a shout out to Stefan Cruysberghs and say thank you for creating this class and posting it up on the net.  Now to keep with the current standard, I will post up my execution of his code.

ThreadedComments.cs (5.98 kb)


If you liked this post, please be sure to subscribe to my RSS Feed.

To Thread or Not To Thread Comments

15. January 2009 03:24 by Scott in   //  Tags: , ,   //   Comments (6)

With building a Social Site you always have to weigh the needs to have interaction with the site.  The current standard for any interaction is the comments section of the sites. The comment section is the talk back, the conversation to the site.  It is what allows for user participation and what most people would declare what Web 2.0 really is.  It allows the comment section to enable user interaction.  In building a site that would be used as a somewhat social site, you have to ask your self do you want to see a conversation another one sided page that has no interaction.  Would you rather get user feedback or just be one sided in everything you write or have to say.  You can't get feedback to see if they enjoy what your posting. You won't get a conversation going which inevitably makes the user want to come back to the site. The fact is, we need comments in the internet, we need conversation.

So in building a site, you have to worry about if you want it to be web 2.0 or web 1.0.  Comments in general are becoming standard on any site out there.  It is on all major social sites and it allows for more interaction between the users.  I don't see any problems with comments.  But I would like to start calling it something different.  A Conversation.  I call it a conversation today because more and more people are commenting.  More and more people are clicking that button to get a notification on what people say.  When you comment you save a part of your self on that site.

The Point

Comments are good, but threaded comments are better.  We are trying to build an online world.  We are trying to create a conversation that any person of any race of any creed and color can voice their ideas on.  Comments allow for anonymous participation in the world of tomorrow.  Free Speech.  Governments ban it and people are killed over what they say, but on the internet, you have all the free speech you want.  To create a conversation, you have to allow talk backs, you have to allow the user to reply to any other user.  You have to make sure a conversation can be had with any other user on the Web 2.0 site.  So in developing my site, I chose to use threaded comments as the default. Flat Comments can be chosen if they want to see flat comments.  Some people just can't handle threaded comments.  But if you think about it, Flat comments can also be threaded.

Just think of when someone posts:

@John,
Your Wrong!

@Tim,
I don't care what you have to say, threaded is better.

A conversation is happening right here if you like it or not. Threaded comments are at least for now the way of the future.  Someone else will invent a better way to have a conversation over a website, but for now threaded is my default and it should be yours too! Help carry on the conversation of the world and thread your comments.

Ask the Readers: What do you think, should threaded comments be a default?

Shameless Plug: DrinkingFor, it is still in Beta.

kick it on DotNetKicks.com

If you liked this post, please be sure to subscribe to my RSS Feed.