You are on page 1of 5

What is a forum?

A forum is essentially a message board that is organized into topics, which allow users to make posts to these topics for everyone to see. Each post can contain any number of comments from our users. Our forum will consist mainly of three things, Topics, Posts, and Comments.

Topics These will be dictated by us when we create the site. Each Topic will contain some number of posts by our users. Posts A post will be created by a user, within a topic. A post contains a title, and a message which becomes the first comment on the post. Each post can contain any number of comments. Comments A comment will be created by a user, within a post. A comment contains a message that is appended to the end of the other comments on the post it is applied to.

Lets take an example of this. For instance, our forum has a topic titled ASP.NET Discussion. Within this topic, a user can make a post with a title such as, Help on Web Forms and add a message like, I need help adding a Web Form to my website. Then, another user can locate that post and add a comment to it saying Simply click add>new item>web form. We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar. What pages will we need? We will need 5 different pages, all based off of a master page, to create our forum.

Default.aspx This will be the home page and will list links and info to the various topics in our forum. Topic.aspx This page will display links to all of the posts within a given topic as well as a link to add a new post to the current topic you are viewing. NewPost.aspx This page will allow the user, if logged in, to add a new post to a given topic. Post.aspx This page will display all of the comments for a given post and will also display a link to add a new comment on the given post. NewComment.aspx This page will allow the user, if logged in, to add a new comment to a given post.

What data will we need to store? We will need to create a database that will store all of the data associated with our forums, and allow us to both organize the data and associate the data with topics, posts, and comments. To do this, we will be creating a database with 3 different tables.

Topics This table will contain all of the data for our topics and will contain 5 columns o TopicId This will be a unique identifier that is associated with the topic. o TopicName This will be the name of the topic that the user sees. o LastPostTitle This will display the title of the last post posted in this topic. o LastPostUserName This will display the username of the person who posted last.

LastPostDateTime This will display the time and date of the last post. Posts This table will contain all of the data for every post made and will contain 5 columns. o PostId This will be a unique identifier that is associated with the post. o TopicId This id will correspond to the TopicId of the topic that the post is posted in. o PostTitle This will be the title of the post that users will see. o PostUserName This will display the name of the user who created the post. o PostDateTime This will display at what time the post was made. Comments This table will contain all of the data for every comment made and will contain 5 columns. o CommentId This will be a unique identifier that is associated with the comment. o PostId This id will correspond to the PostId of the post that this comment was added to. o CommentUserName This will display the name of the user who added the comment. o CommentMessage This will display the message of the comment added. o CommentDateTime This will display at what time the comment was made.
o

Creating our Master Page At this point in the tutorial I have created a new ASP.NET Empty Web Site. What we want to do first is create a Master Page with a title and link to the home page. To do this: 1. 2. 3. 4. Right click the project in your Solution Explorer. Click Add New Item Select Master Page, keeping the default name MasterPage.master. Click Add.

The next thing we need to do here is add some content to the page. To do this, open up the MasterPage to Design mode and: 1. Select somewhere above the ContentPlaceHolder1. 2. From the top menu select Table -> Insert Table. 3. Create a table with 2 rows and 2 columns, and a width of 100% and hit OK.

4. Select the 2 cells in the top row and merge them together. 5. Add in the text ASP.NET Forums Tutorial and change the font size to xx-large.

6. In the bottom left cell, drag and drop a Hyperlink Control and change the Text property to Home and the NavigateUrl property to Default.aspx. 7. In the bottom right cell, drag the ContentPlaceHolder1, which will be where the content from our pages show up on the master page.

Try Server Intellect for Windows Server Hosting. Quality and Quantity! Adding the Database The next thing we want to do is setup our database. To do this: 1. 2. 3. 4. Right click the project in your Solution Explorer. Select Add ASP.NET Folder and click App_Data. Right click the App_Data folder and select Add New Item Select a SQL Server Database, name it ForumDB and click Add.

This should take you to the Server or Database Explorer which shows all of the different folders within the database we have added. What we want to do next is add in some tables to hold our data. The first table we are going to add is the Topics table. To do this, right click the Tables folder and select Add New Table. Create the following columns with their respective types: Column Name Data Type TopcId TopicName LastPostTitle int varchar(50) varchar(255)

LastPostUserName varchar(50) LastPostDateTime smalldatetime Save the table as Topics. Next, we need to set the TopicId to the primary key of this table. To do this: 1. Right click the TopicId row and select Set Primary Key. 2. Under the Column Properties, set the Is Identity property under Identity Specification to Yes. The next table we will add is the Posts table. To do this, right click the Tables folder and select Add New Table. Create the following columns with their respective types: Column Name Data Type

PostId TopicId PostTitle

int int varchar(255)

PostUserName varchar(50) PostDateTime smalldatetime Save the table as Posts. Next, we need to set the PostId to the primary key of this table. To do this: 1. Right click the PostId row and select Set Primary Key. 2. Under the Column Properties, set the Is Identity property under the Identity Specification to Yes. The next table we will add is the Comments table. To do this, right click the Tables folder and select Add New Table. Create the following columns with their respective types: Column Name Data Type CommentId PostId int int

CommentUserName varchar(50) CommentMessage varchar(MAX)

CommentDateTime smalldatetime Save the table as Comments. Next, we need to set the CommentId to the primary key of this table. To do this: 1. Right click the CommentId row and select Set Primary Key. 2. Under the Column Properties, set the Is Identity property under the identity Specification to Yes. Once this is setup we are ready to begin designing our web pages. Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team. The MasterPage.master source looks like this:
<head runat="server"> <title></title> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder> <style type="text/css"> .style1 {

width: 100%; } .style2 { width: 43px; } </style> </head> <body> <form id="form1" runat="server"> <div> <table class="style1"> <tr> <td colspan="2" style="font-size: xx-large"> ASP.NET Forums Tutorial</td> </tr> <tr> <td class="style2"> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl ="~/Default.aspx">Home</asp:HyperLink> </td> <td> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </td> </tr> </table> <br /> </div> </form> </body>

You might also like